Ticket #7885: duplicate_field_declarations_2.diff
File duplicate_field_declarations_2.diff, 2.4 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/validation.py
1 try: 2 set 3 except NameError: 4 from sets import Set as set # Python 2.3 fallback 1 5 2 6 from django.core.exceptions import ImproperlyConfigured 3 7 from django.db import models … … 165 169 _check_form_field_existsw('fields', field) 166 170 if cls.fieldsets: 167 171 raise ImproperlyConfigured('Both fieldsets and fields are specified in %s.' % cls.__name__) 172 if len(cls.fields) > len(set(cls.fields)): 173 raise ImproperlyConfigured('There are duplicate field(s) in %s.fields' % cls.__name__) 168 174 169 175 # fieldsets 170 176 if cls.fieldsets: # default value is None … … 179 185 raise ImproperlyConfigured("`fields` key is required in " 180 186 "%s.fieldsets[%d][1] field options dict." 181 187 % (cls.__name__, idx)) 182 for field in flatten_fieldsets(cls.fieldsets): 188 flattened_fieldsets = flatten_fieldsets(cls.fieldsets) 189 if len(flattened_fieldsets) > len(set(flattened_fieldsets)): 190 raise ImproperlyConfigured('There are duplicate field(s) in %s.fieldsets' % cls.__name__) 191 for field in flattened_fieldsets: 183 192 _check_form_field_existsw("fieldsets[%d][1]['fields']" % idx, field) 184 193 185 194 # form -
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):