From 838c93563d578a030295b0a9820decd0adf488c6 Mon Sep 17 00:00:00 2001 From: Sander Claus Date: Sun, 20 Jul 2025 12:29:32 +0200 Subject: [PATCH 1/4] Fixed #36509: added id attribute to table headers. --- django/contrib/admin/templates/admin/change_list_results.html | 2 +- django/contrib/admin/templatetags/admin_list.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/templates/admin/change_list_results.html b/django/contrib/admin/templates/admin/change_list_results.html index bea4a5b859..043be07793 100644 --- a/django/contrib/admin/templates/admin/change_list_results.html +++ b/django/contrib/admin/templates/admin/change_list_results.html @@ -18,7 +18,7 @@ {% endif %} -
{% if header.sortable %}{{ header.text|capfirst }}{% else %}{{ header.text|capfirst }}{% endif %}
+
{% if header.sortable %}{{ header.text|capfirst }}{% else %}{{ header.text|capfirst }}{% endif %}
{% endfor %} diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index 1e6f8bf298..5c81050554 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -26,7 +26,7 @@ from django.urls import NoReverseMatch from django.utils import formats, timezone from django.utils.html import format_html from django.utils.safestring import mark_safe -from django.utils.text import capfirst +from django.utils.text import capfirst, slugify from django.utils.translation import gettext as _ from .base import InclusionAdminNode @@ -167,6 +167,7 @@ def result_headers(cl): yield { "text": text, + "id": slugify(text), "sortable": True, "sorted": is_sorted, "ascending": order_type == "asc", From 6cb6487e6f837ad2ca1e3c08633d80eb096dab07 Mon Sep 17 00:00:00 2001 From: Sander Claus Date: Sun, 20 Jul 2025 12:32:57 +0200 Subject: [PATCH 2/4] Fixed #36509: set column header id as field aria attribute. --- django/contrib/admin/templatetags/admin_list.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index 5c81050554..c57c4828a2 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -220,6 +220,9 @@ def items_for_result(cl, result, form): link_to_changelist = link_in_col(first, field_name, cl) try: f, attr, value = lookup_field(field_name, result, cl.model_admin) + label, label_attr = label_for_field( + field_name, cl.model, model_admin=cl.model_admin, return_attr=True + ) except ObjectDoesNotExist: result_repr = empty_value_display else: @@ -306,6 +309,8 @@ def items_for_result(cl, result, form): ) ): bf = form[field_name] + if not label_attr: + bf.field.widget.attrs["aria-labelledby"] = slugify(label) result_repr = mark_safe(str(bf.errors) + str(bf)) yield format_html("{}", row_class, result_repr) if form and not form[cl.model._meta.pk.name].is_hidden: From 14a0d4bb67ea5da31887ec8991947e59f02eb5e9 Mon Sep 17 00:00:00 2001 From: Sander Claus Date: Sun, 20 Jul 2025 13:50:10 +0200 Subject: [PATCH 3/4] Fixed #36509: added atribute to test. --- tests/admin_changelist/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index cd2fe7c645..061ea78fe3 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -430,7 +430,7 @@ class ChangeListTests(TestCase): # make sure that list editable fields are rendered in divs correctly editable_name_field = ( - '' ) self.assertInHTML( From 8fc1fab66faf943e99452b6358810641c315d426 Mon Sep 17 00:00:00 2001 From: Sander Claus Date: Sun, 20 Jul 2025 14:11:32 +0200 Subject: [PATCH 4/4] Fixed #36509: fixed flake8 error: line too long. --- tests/admin_changelist/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index 061ea78fe3..2b0d304451 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -430,8 +430,8 @@ class ChangeListTests(TestCase): # make sure that list editable fields are rendered in divs correctly editable_name_field = ( - '' + '' ) self.assertInHTML( '%s' % editable_name_field,