mirror of https://github.com/django/django.git
Fixed #26632 -- Skipped admin.E111 list_display_links check if get_list_display() is overridden.
This commit is contained in:
parent
bf4516a628
commit
da79240050
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
Loading…
Reference in New Issue