diff --git a/django/contrib/admin/templates/admin/widgets/foreign_key_raw_id.html b/django/contrib/admin/templates/admin/widgets/foreign_key_raw_id.html index be93e0581d..a6eba931c4 100644 --- a/django/contrib/admin/templates/admin/widgets/foreign_key_raw_id.html +++ b/django/contrib/admin/templates/admin/widgets/foreign_key_raw_id.html @@ -1,2 +1,2 @@ -{% include 'django/forms/widgets/input.html' %}{% if related_url %}{% endif %}{% if link_label %} -{% if link_url %}{{ link_label }}{% else %}{{ link_label }}{% endif %}{% endif %} +{% if related_url %}
{% endif %}{% include 'django/forms/widgets/input.html' %}{% if related_url %}{% endif %}{% if link_label %} +{% if link_url %}{{ link_label }}{% else %}{{ link_label }}{% endif %}{% endif %}{% if related_url %}
{% endif %} diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 6f009a6f3f..517e060b80 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -23,6 +23,7 @@ from django.db.models import ( UUIDField, ) from django.test import SimpleTestCase, TestCase, ignore_warnings, override_settings +from django.test.selenium import screenshot_cases from django.test.utils import requires_tz_support from django.urls import reverse from django.utils import translation @@ -684,21 +685,21 @@ class ForeignKeyRawIdWidgetTest(TestCase): w = widgets.ForeignKeyRawIdWidget(rel_uuid, widget_admin_site) self.assertHTMLEqual( w.render("test", band.uuid, attrs={}), - '' ' ' 'Linkin Park' - "" % {"banduuid": band.uuid, "bandpk": band.pk}, + "" % {"banduuid": band.uuid, "bandpk": band.pk}, ) rel_id = ReleaseEvent._meta.get_field("album").remote_field w = widgets.ForeignKeyRawIdWidget(rel_id, widget_admin_site) self.assertHTMLEqual( w.render("test", None, attrs={}), - '' + '
' '', + 'id="lookup_id_test" title="Lookup">
', ) def test_relations_to_non_primary_key(self): @@ -711,12 +712,12 @@ class ForeignKeyRawIdWidgetTest(TestCase): w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site) self.assertHTMLEqual( w.render("test", core.parent_id, attrs={}), - '' '' ' ' - "Apple" % {"pk": apple.pk}, + "Apple" % {"pk": apple.pk}, ) def test_fk_related_model_not_in_admin(self): @@ -760,12 +761,12 @@ class ForeignKeyRawIdWidgetTest(TestCase): ) self.assertHTMLEqual( w.render("test", child_of_hidden.parent_id, attrs={}), - '' '' ' ' - "Hidden" % {"pk": hidden.pk}, + "Hidden" % {"pk": hidden.pk}, ) def test_render_unsafe_limit_choices_to(self): @@ -773,10 +774,10 @@ class ForeignKeyRawIdWidgetTest(TestCase): w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site) self.assertHTMLEqual( w.render("test", None), - '\n' + '
' '', + 'title="Lookup">
', ) def test_render_fk_as_pk_model(self): @@ -784,9 +785,9 @@ class ForeignKeyRawIdWidgetTest(TestCase): w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site) self.assertHTMLEqual( w.render("test", None), - '\n' + '
' '', + 'class="related-lookup" id="lookup_id_test" title="Lookup">
', ) @@ -804,10 +805,10 @@ class ManyToManyRawIdWidgetTest(TestCase): self.assertHTMLEqual( w.render("test", [m1.pk, m2.pk], attrs={}), ( - '' '' + ' id="lookup_id_test" title="Lookup">' ) % {"m1pk": m1.pk, "m2pk": m2.pk}, ) @@ -815,10 +816,10 @@ class ManyToManyRawIdWidgetTest(TestCase): self.assertHTMLEqual( w.render("test", [m1.pk]), ( - '' '' + ' id="lookup_id_test" title="Lookup">' ) % {"m1pk": m1.pk}, ) @@ -1680,6 +1681,7 @@ class AdminRawIdWidgetSeleniumTests(AdminWidgetSeleniumTestCase): Band.objects.create(id=42, name="Bogey Blues") Band.objects.create(id=98, name="Green Potatoes") + @screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"]) def test_ForeignKey(self): from selenium.webdriver.common.by import By @@ -1688,6 +1690,7 @@ class AdminRawIdWidgetSeleniumTests(AdminWidgetSeleniumTestCase): self.live_server_url + reverse("admin:admin_widgets_event_add") ) main_window = self.selenium.current_window_handle + self.take_screenshot("raw_id_widget") # No value has been selected yet self.assertEqual(