mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #22792 -- Updated checks for list_display_links in model admin
This commit is contained in:
parent
34f4fd7024
commit
d8f19bb3b6
@ -779,7 +779,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
|
|||||||
obj=cls,
|
obj=cls,
|
||||||
id='admin.E122',
|
id='admin.E122',
|
||||||
),
|
),
|
||||||
elif field_name in cls.list_display_links:
|
elif cls.list_display_links and field_name in cls.list_display_links:
|
||||||
return [
|
return [
|
||||||
checks.Error(
|
checks.Error(
|
||||||
"The value of '%s' cannot be in both 'list_editable' and 'list_display_links'." % field_name,
|
"The value of '%s' cannot be in both 'list_editable' and 'list_display_links'." % field_name,
|
||||||
@ -788,7 +788,10 @@ class ModelAdminChecks(BaseModelAdminChecks):
|
|||||||
id='admin.E123',
|
id='admin.E123',
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
elif not cls.list_display_links and cls.list_display[0] in cls.list_editable:
|
# Check that list_display_links is set, and that the first values of list_editable and list_display are
|
||||||
|
# not the same. See ticket #22792 for the use case relating to this.
|
||||||
|
elif (cls.list_display[0] in cls.list_editable and cls.list_display[0] != cls.list_editable[0] and
|
||||||
|
cls.list_display_links is not None):
|
||||||
return [
|
return [
|
||||||
checks.Error(
|
checks.Error(
|
||||||
"The value of '%s' refers to the first field in 'list_display' ('%s'), "
|
"The value of '%s' refers to the first field in 'list_display' ('%s'), "
|
||||||
|
@ -1518,3 +1518,27 @@ class CustomModelAdminTests(CheckTestCase):
|
|||||||
validator_class = CustomValidator
|
validator_class = CustomValidator
|
||||||
|
|
||||||
self.assertIsInvalid(CustomModelAdmin, ValidationTestModel, 'error!')
|
self.assertIsInvalid(CustomModelAdmin, ValidationTestModel, 'error!')
|
||||||
|
|
||||||
|
|
||||||
|
class ListDisplayEditableTests(CheckTestCase):
|
||||||
|
def test_list_display_links_is_none(self):
|
||||||
|
"""
|
||||||
|
list_display and list_editable can contain the same values
|
||||||
|
when list_display_links is None
|
||||||
|
"""
|
||||||
|
class ProductAdmin(ModelAdmin):
|
||||||
|
list_display = ['name', 'slug', 'pub_date']
|
||||||
|
list_editable = list_display
|
||||||
|
list_display_links = None
|
||||||
|
self.assertIsValid(ProductAdmin, ValidationTestModel)
|
||||||
|
|
||||||
|
def test_list_display_same_as_list_editable(self):
|
||||||
|
"""
|
||||||
|
The first item in list_display can be the same as the first
|
||||||
|
in list_editable
|
||||||
|
"""
|
||||||
|
class ProductAdmin(ModelAdmin):
|
||||||
|
list_display = ['name', 'slug', 'pub_date']
|
||||||
|
list_editable = ['name', 'slug']
|
||||||
|
list_display_links = ['pub_date']
|
||||||
|
self.assertIsValid(ProductAdmin, ValidationTestModel)
|
||||||
|
Loading…
Reference in New Issue
Block a user