From 93c8e2d50d636e46ded9c6cfed0b0c4623457b74 Mon Sep 17 00:00:00 2001 From: David Szotten Date: Thu, 2 Mar 2017 15:25:05 +0000 Subject: [PATCH] [1.11.x] Fixed #27889 -- Fixed incorrect check error if ModelAdmin.ordering refers to 'pk'. Backport of d82ee32aac323b7260cc95278c69b81d98dbd00a from master --- django/contrib/admin/checks.py | 3 ++- tests/modeladmin/test_checks.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index 286c1169a4..f000fc269b 100644 --- a/django/contrib/admin/checks.py +++ b/django/contrib/admin/checks.py @@ -468,7 +468,8 @@ class BaseModelAdminChecks(object): else: if field_name.startswith('-'): field_name = field_name[1:] - + if field_name == 'pk': + return [] try: model._meta.get_field(field_name) except FieldDoesNotExist: diff --git a/tests/modeladmin/test_checks.py b/tests/modeladmin/test_checks.py index 0c66544b6b..ad43f34837 100644 --- a/tests/modeladmin/test_checks.py +++ b/tests/modeladmin/test_checks.py @@ -796,7 +796,7 @@ class OrderingCheckTests(CheckTestCase): def test_valid_case(self): class TestModelAdmin(ModelAdmin): - ordering = ('name',) + ordering = ('name', 'pk') self.assertIsValid(TestModelAdmin, ValidationTestModel)