summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHisham Mahmood <hishammahmood41@gmail.com>2024-07-17 15:50:45 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-07-18 08:30:53 +0200
commitc3d3af8ea369e16263c8330b1745ba101d1c8d62 (patch)
tree0a80e5e7b92bffdb98ebe08691a083851165ccdc /tests
parentfe9bf0cef50e8e97e76424df98fd841fdc211e94 (diff)
[5.0.x] 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. Backport of 182f262b15882649bbc39d769f9b721cf3660f6f from main.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_changelist/admin.py9
-rw-r--r--tests/admin_changelist/models.py11
-rw-r--r--tests/admin_changelist/tests.py23
3 files changed, 42 insertions, 1 deletions
diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
index 8ffc45e391..02cf9a6df2 100644
--- a/tests/admin_changelist/admin.py
+++ b/tests/admin_changelist/admin.py
@@ -3,7 +3,7 @@ from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.core.paginator import Paginator
-from .models import Band, Child, Event, Parent, ProxyUser, Swallow
+from .models import Band, Child, Event, GrandChild, Parent, ProxyUser, Swallow
site = admin.AdminSite(name="admin")
@@ -53,6 +53,13 @@ class ChildAdmin(admin.ModelAdmin):
return super().get_queryset(request).select_related("parent")
+class GrandChildAdmin(admin.ModelAdmin):
+ list_display = ["name"]
+
+
+site.register(GrandChild, GrandChildAdmin)
+
+
class CustomPaginationAdmin(ChildAdmin):
paginator = CustomPaginator
diff --git a/tests/admin_changelist/models.py b/tests/admin_changelist/models.py
index aa4656e93e..78e65ab878 100644
--- a/tests/admin_changelist/models.py
+++ b/tests/admin_changelist/models.py
@@ -19,6 +19,17 @@ class Child(models.Model):
age = models.IntegerField(null=True, blank=True)
+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 4caefdb9e4..33b95bc841 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -43,6 +43,7 @@ from .admin import (
EmptyValueChildAdmin,
EventAdmin,
FilteredChildAdmin,
+ GrandChildAdmin,
GroupAdmin,
InvitationAdmin,
NoListDisplayLinksParentAdmin,
@@ -62,6 +63,7 @@ from .models import (
CustomIdUser,
Event,
Genre,
+ GrandChild,
Group,
Invitation,
Membership,
@@ -341,6 +343,27 @@ 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, "")
+ 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