mirror of
https://github.com/django/django.git
synced 2025-10-27 23:56:08 +00:00
Fixed #22018 -- Fixed checks for ModelAdmin.fields not handling sub-lists.
Flatten a level of sublists before checking for duplicate fields.
When given sublists such as:
```python
class FooAdmin(admin.ModelAdmin):
fields = ('one', ('one', 'two'))
```
The previous code did not correctly detect the duplicated 'one' field.
Thanks to jwa for the report.
This commit is contained in:
committed by
Baptiste Mispelon
parent
2ebccebf06
commit
23b781cc3d
@@ -463,3 +463,37 @@ class SystemChecksTestCase(TestCase):
|
||||
)
|
||||
]
|
||||
self.assertEqual(errors, expected)
|
||||
|
||||
def test_check_sublists_for_duplicates(self):
|
||||
class MyModelAdmin(admin.ModelAdmin):
|
||||
fields = ['state', ['state']]
|
||||
|
||||
errors = MyModelAdmin.check(model=Song)
|
||||
expected = [
|
||||
checks.Error(
|
||||
'There are duplicate field(s) in "fields".',
|
||||
hint=None,
|
||||
obj=MyModelAdmin,
|
||||
id='admin.E006'
|
||||
)
|
||||
]
|
||||
self.assertEqual(errors, expected)
|
||||
|
||||
def test_check_fieldset_sublists_for_duplicates(self):
|
||||
class MyModelAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
(None, {
|
||||
'fields': ['title', 'album', ('title', 'album')]
|
||||
}),
|
||||
]
|
||||
|
||||
errors = MyModelAdmin.check(model=Song)
|
||||
expected = [
|
||||
checks.Error(
|
||||
'There are duplicate field(s) in "fieldsets[0][1]".',
|
||||
hint=None,
|
||||
obj=MyModelAdmin,
|
||||
id='admin.E012'
|
||||
)
|
||||
]
|
||||
self.assertEqual(errors, expected)
|
||||
|
||||
Reference in New Issue
Block a user