Ticket #7885: duplicate_field_declarations.diff
File duplicate_field_declarations.diff, 2.5 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.forms.models import BaseModelForm, BaseModelFormSet, fields_for_model … … 165 165 _check_form_field_existsw('fields', field) 166 166 if cls.fieldsets: 167 167 raise ImproperlyConfigured('Both fieldsets and fields are specified in %s.' % cls.__name__) 168 if len(cls.fields) > len(sets.Set(cls.fields)): 169 raise ImproperlyConfigured('There are duplicate field(s) in %s.fields' % cls.__name__) 168 170 169 171 # fieldsets 170 172 if cls.fieldsets: # default value is None … … 179 181 raise ImproperlyConfigured("`fields` key is required in " 180 182 "%s.fieldsets[%d][1] field options dict." 181 183 % (cls.__name__, idx)) 182 for field in flatten_fieldsets(cls.fieldsets): 184 flattened_fieldsets = flatten_fieldsets(cls.fieldsets) 185 if len(flattened_fieldsets) > len(sets.Set(flattened_fieldsets)): 186 raise ImproperlyConfigured('There are duplicate field(s) in %s.fieldsets' % cls.__name__) 187 for field in flattened_fieldsets: 183 188 _check_form_field_existsw("fieldsets[%d][1]['fields']" % idx, field) 184 189 185 190 # form -
django/tests/regressiontests/modeladmin/models.py
346 346 ... 347 347 ImproperlyConfigured: Both fieldsets and fields are specified in ValidationTestModelAdmin. 348 348 349 >>> class ValidationTestModelAdmin(ModelAdmin): 350 ... fieldsets = [(None, {'fields': ['name', 'name']})] 351 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 352 Traceback (most recent call last): 353 ... 354 ImproperlyConfigured: There are duplicate field(s) in ValidationTestModelAdmin.fieldsets 355 356 >>> class ValidationTestModelAdmin(ModelAdmin): 357 ... fields = ["name", "name"] 358 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 359 Traceback (most recent call last): 360 ... 361 ImproperlyConfigured: There are duplicate field(s) in ValidationTestModelAdmin.fields 362 349 363 # form 350 364 351 365 >>> class FakeForm(object):