mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26: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
@@ -5,8 +5,8 @@ from datetime import datetime
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin import helpers
|
||||
from django.contrib.admin.utils import (display_for_field, flatten_fieldsets,
|
||||
label_for_field, lookup_field, NestedObjects)
|
||||
from django.contrib.admin.utils import (display_for_field, flatten,
|
||||
flatten_fieldsets, label_for_field, lookup_field, NestedObjects)
|
||||
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
|
||||
from django.contrib.sites.models import Site
|
||||
from django.db import models, DEFAULT_DB_ALIAS
|
||||
@@ -323,6 +323,17 @@ class UtilTests(SimpleTestCase):
|
||||
self.assertHTMLEqual(helpers.AdminField(form, 'cb', is_first=False).label_tag(),
|
||||
'<label for="id_cb" class="vCheckboxLabel required inline">&cb</label>')
|
||||
|
||||
def test_flatten(self):
|
||||
flat_all = ['url', 'title', 'content', 'sites']
|
||||
inputs = (
|
||||
((), []),
|
||||
(('url', 'title', ('content', 'sites')), flat_all),
|
||||
(('url', 'title', 'content', 'sites'), flat_all),
|
||||
((('url', 'title'), ('content', 'sites')), flat_all)
|
||||
)
|
||||
for orig, expected in inputs:
|
||||
self.assertEqual(flatten(orig), expected)
|
||||
|
||||
def test_flatten_fieldsets(self):
|
||||
"""
|
||||
Regression test for #18051
|
||||
|
||||
Reference in New Issue
Block a user