1
0
mirror of https://github.com/django/django.git synced 2025-10-28 16:16:12 +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:
Aaron France
2014-02-15 11:28:09 +01:00
committed by Baptiste Mispelon
parent 2ebccebf06
commit 23b781cc3d
4 changed files with 75 additions and 18 deletions

View File

@@ -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)