diff options
| author | Hisham Mahmood <hishammahmood41@gmail.com> | 2024-07-17 18:50:45 +0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-07-18 08:09:37 +0200 |
| commit | 182f262b15882649bbc39d769f9b721cf3660f6f (patch) | |
| tree | c9b0680e663c00f6f0ff2cf136ee797239d13b90 /tests/admin_changelist | |
| parent | 0e49a8c3bd9119795525d9f076f73740741479b7 (diff) | |
Fixed #35606, Refs #34045 -- Fixed rendering of ModelAdmin.action_checkbox for models with a __html__ method.
Thank you Claude Paroz for the report.
Regression in 85366fbca723c9b37d0ac9db1d44e3f1cb188db2.
Diffstat (limited to 'tests/admin_changelist')
| -rw-r--r-- | tests/admin_changelist/models.py | 6 | ||||
| -rw-r--r-- | tests/admin_changelist/tests.py | 27 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/admin_changelist/models.py b/tests/admin_changelist/models.py index 290a3ea4ec..78e65ab878 100644 --- a/tests/admin_changelist/models.py +++ b/tests/admin_changelist/models.py @@ -23,6 +23,12 @@ class GrandChild(models.Model): parent = models.ForeignKey(Child, models.SET_NULL, editable=False, null=True) name = models.CharField(max_length=30, blank=True) + def __str__(self): + return self.name + + def __html__(self): + return f'<h2 class="main">{self.name}</h2>' + class Genre(models.Model): name = models.CharField(max_length=20) diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index bf85cf038f..4d8845e11e 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -364,6 +364,33 @@ class ChangeListTests(TestCase): table_output, ) + def test_action_checkbox_for_model_with_dunder_html(self): + grandchild = GrandChild.objects.create(name="name") + request = self._mocked_authenticated_request("/grandchild/", self.superuser) + m = GrandChildAdmin(GrandChild, custom_site) + cl = m.get_changelist_instance(request) + cl.formset = None + template = Template( + "{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}" + ) + context = Context({"cl": cl, "opts": GrandChild._meta}) + table_output = template.render(context) + link = reverse( + "admin:admin_changelist_grandchild_change", args=(grandchild.id,) + ) + row_html = build_tbody_html( + grandchild, + link, + "name", + '<td class="field-parent__name">-</td>' + '<td class="field-parent__parent__name">-</td>', + ) + self.assertNotEqual( + table_output.find(row_html), + -1, + "Failed to find expected row element: %s" % table_output, + ) + def test_result_list_editable_html(self): """ Regression tests for #11791: Inclusion tag result_list generates a |
