diff --git a/AUTHORS b/AUTHORS index 3edfbecf2ab4..eeb2e7acbbc9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -41,6 +41,7 @@ answer newbie questions, and generally made Django that much better: Akash Kumar Sen Akis Kesoglou Aksel Ethem + Akshat Sparsh Akshesh Doshi alang@bright-green.com Alasdair Nicol diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index aafbae9d90cb..211a2533b3cd 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -116,7 +116,9 @@ def result_headers(cl): # Set ordering for attr that is a property, if defined. if isinstance(attr, property) and hasattr(attr, "fget"): admin_order_field = getattr(attr.fget, "admin_order_field", None) - if not admin_order_field and LOOKUP_SEP not in field_name: + if not admin_order_field and not ( + LOOKUP_SEP in field_name and isinstance(attr, models.Field) + ): is_field_sortable = False if not is_field_sortable: diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index f1d1abc0b0a5..f88982e10ba7 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -4,7 +4,7 @@ from django.contrib import admin from django.contrib.admin.models import LogEntry from django.contrib.admin.options import IncorrectLookupParameters -from django.contrib.admin.templatetags.admin_list import pagination +from django.contrib.admin.templatetags.admin_list import pagination, result_headers from django.contrib.admin.tests import AdminSeleniumTestCase from django.contrib.admin.views.main import ( ALL_VAR, @@ -115,6 +115,20 @@ def test_repr(self): cl = m.get_changelist_instance(request) self.assertEqual(repr(cl), "") + def test_default_str_column_is_not_sortable(self): + GrandChild.objects.create(name="Grandchild") + m = admin.ModelAdmin(GrandChild, custom_site) + request = self._mocked_authenticated_request("/grandchild/", self.superuser) + cl = m.get_changelist_instance(request) + headers = list(result_headers(cl)) + self.assertEqual(cl.list_display[1], "__str__") + self.assertIs(headers[1]["sortable"], False) + response = m.changelist_view(request) + self.assertContains(response, '') + self.assertNotContains( + response, '' + ) + def test_specified_ordering_by_f_expression(self): class OrderedByFBandAdmin(admin.ModelAdmin): list_display = ["name", "genres", "nr_of_members"] @@ -1726,6 +1740,13 @@ def test_list_display_related_field(self): response = m.changelist_view(request) self.assertContains(response, parent.name) self.assertContains(response, child.name) + self.assertContains( + response, '' + ) + self.assertContains( + response, + '', + ) def test_list_display_related_field_null(self): GrandChild.objects.create(name="I am parentless", parent=None) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 92392c43e9cf..4ba2fa225549 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -4323,6 +4323,11 @@ def test_generic_content_object_in_list_display(self): FunkyTag.objects.create(content_object=self.pl3, name="hott") response = self.client.get(reverse("admin:admin_views_funkytag_changelist")) self.assertContains(response, "%s" % self.pl3) + self.assertContains(response, '') + self.assertNotContains( + response, + '', + ) @override_settings(ROOT_URLCONF="admin_views.urls")