Ticket #4305: 4305.duplicate_fieldnames.diff
File 4305.duplicate_fieldnames.diff, 2.9 KB (added by , 16 years ago) |
---|
-
django/django/contrib/admin/validation.py
1 1 import sets 2 2 from django.core.exceptions import ImproperlyConfigured 3 3 from django.db import models 4 4 from django.newforms.models import BaseModelForm, BaseInlineFormset … … 168 168 raise ImproperlyConfigured("`fields` key is required in " 169 169 "%s.fieldsets[%d][1] field options dict." 170 170 % (cls.__name__, idx)) 171 for field in flatten_fieldsets(cls.fieldsets): 171 flattened_fieldsets = flatten_fieldsets(cls.fieldsets) 172 if len(flattened_fieldsets) > len(sets.Set(flattened_fieldsets)): 173 raise ImproperlyConfigured('There are duplicate field(s) in %s.fieldsets' % cls.__name__) 174 for field in flattened_fieldsets: 172 175 _check_field_existsw("fieldsets[%d][1]['fields']" % idx, field) 173 176 174 177 # form -
django/tests/regressiontests/modeladmin/models.py
337 337 ... fieldsets = (("General", {"fields": ("name",)}),) 338 338 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 339 339 340 If there are duplicate fields in the fieldsets declaration, an exception 341 should be raised. 342 >>> class ValidationTestModelAdmin(ModelAdmin): 343 ... fieldsets = [(None, {'fields': ['name', 'name']})] 344 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 345 Traceback (most recent call last): 346 ... 347 ImproperlyConfigured: There are duplicate field(s) in ValidationTestModelAdmin.fieldsets 348 340 349 # form 341 350 342 351 >>> class FakeForm(object): -
django/docs/admin.txt
102 102 that isn't an ``AutoField`` and has ``editable=True``, in a single fieldset, 103 103 in the same order as the fields are defined in the model. 104 104 105 ``fieldsets`` should not contain duplicates (a duplicate meaning that a same field 106 appears multiple times in the declaration). If a duplicate is found then an exception 107 will be raised. For example, the following would **not** be valid, as the ``pub_date`` 108 field appears twice:: 109 110 class PollAdmin(admin.ModelAdmin): 111 fieldsets = ( 112 (None, { 113 'fields': ('pub_date', 'question') 114 }), 115 ('Date information', { 116 'fields': ('pub_date',) 117 }), 118 ) 119 105 120 The ``field_options`` dictionary can have the following keys: 106 121 107 122 ``fields``