diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index 91fa85f0f8..90f5396b19 100644 --- a/django/contrib/admin/checks.py +++ b/django/contrib/admin/checks.py @@ -655,16 +655,21 @@ class ModelAdminChecks(BaseModelAdminChecks): def _check_list_display_links(self, obj): """ Check that list_display_links is a unique subset of list_display. """ + from django.contrib.admin.options import ModelAdmin if obj.list_display_links is None: return [] elif not isinstance(obj.list_display_links, (list, tuple)): return must_be('a list, a tuple, or None', option='list_display_links', obj=obj, id='admin.E110') - else: + # Check only if ModelAdmin.get_list_display() isn't overridden. + elif obj.get_list_display.__code__ is ModelAdmin.get_list_display.__code__: + # Use obj.get_list_display.__func__ is ModelAdmin.get_list_display + # when dropping PY2. return list(chain(*[ self._check_list_display_links_item(obj, field_name, "list_display_links[%d]" % index) for index, field_name in enumerate(obj.list_display_links) ])) + return [] def _check_list_display_links_item(self, obj, field_name, label): if field_name not in obj.list_display: diff --git a/tests/modeladmin/test_checks.py b/tests/modeladmin/test_checks.py index 89effa9bff..0c66544b6b 100644 --- a/tests/modeladmin/test_checks.py +++ b/tests/modeladmin/test_checks.py @@ -526,6 +526,35 @@ class ListDisplayLinksCheckTests(CheckTestCase): self.assertIsValid(TestModelAdmin, ValidationTestModel) + def test_list_display_links_check_skipped_if_get_list_display_overridden(self): + """ + list_display_links check is skipped if get_list_display() is overridden. + """ + class TestModelAdmin(ModelAdmin): + list_display_links = ['name', 'subtitle'] + + def get_list_display(self, request): + pass + + self.assertIsValid(TestModelAdmin, ValidationTestModel) + + def test_list_display_link_checked_for_list_tuple_if_get_list_display_overridden(self): + """ + list_display_links is checked for list/tuple/None even if + get_list_display() is overridden. + """ + class TestModelAdmin(ModelAdmin): + list_display_links = 'non-list/tuple' + + def get_list_display(self, request): + pass + + self.assertIsInvalid( + TestModelAdmin, ValidationTestModel, + "The value of 'list_display_links' must be a list, a tuple, or None.", + 'admin.E110' + ) + class ListFilterTests(CheckTestCase):