mirror of
https://github.com/django/django.git
synced 2025-10-26 15:16:09 +00:00
Fixed #12237 -- Improved the error message for m2m fields with an explicit through model being listed in admin fieldsets. Thanks to Pyth for the report and Ramiro Morales for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11744 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -198,7 +198,9 @@ def validate_base(cls, model):
|
||||
check_formfield(cls, model, opts, 'fields', field)
|
||||
f = get_field(cls, model, opts, 'fields', field)
|
||||
if isinstance(f, models.ManyToManyField) and not f.rel.through._meta.auto_created:
|
||||
raise ImproperlyConfigured("'%s.fields' can't include the ManyToManyField field '%s' because '%s' manually specifies a 'through' model." % (cls.__name__, field, field))
|
||||
raise ImproperlyConfigured("'%s.fields' can't include the ManyToManyField "
|
||||
"field '%s' because '%s' manually specifies "
|
||||
"a 'through' model." % (cls.__name__, field, field))
|
||||
if cls.fieldsets:
|
||||
raise ImproperlyConfigured('Both fieldsets and fields are specified in %s.' % cls.__name__)
|
||||
if len(cls.fields) > len(set(cls.fields)):
|
||||
@@ -217,11 +219,23 @@ def validate_base(cls, model):
|
||||
raise ImproperlyConfigured("'fields' key is required in "
|
||||
"%s.fieldsets[%d][1] field options dict."
|
||||
% (cls.__name__, idx))
|
||||
for field in fieldset[1]['fields']:
|
||||
check_formfield(cls, model, opts, "fieldsets[%d][1]['fields']" % idx, field)
|
||||
try:
|
||||
f = opts.get_field(field)
|
||||
if isinstance(f, models.ManyToManyField) and not f.rel.through._meta.auto_created:
|
||||
raise ImproperlyConfigured("'%s.fieldsets[%d][1]['fields']' "
|
||||
"can't include the ManyToManyField field '%s' because "
|
||||
"'%s' manually specifies a 'through' model." % (
|
||||
cls.__name__, idx, field, field))
|
||||
except models.FieldDoesNotExist:
|
||||
# If we can't find a field on the model that matches,
|
||||
# it could be an extra field on the form.
|
||||
pass
|
||||
flattened_fieldsets = flatten_fieldsets(cls.fieldsets)
|
||||
if len(flattened_fieldsets) > len(set(flattened_fieldsets)):
|
||||
raise ImproperlyConfigured('There are duplicate field(s) in %s.fieldsets' % cls.__name__)
|
||||
for field in flattened_fieldsets:
|
||||
check_formfield(cls, model, opts, "fieldsets[%d][1]['fields']" % idx, field)
|
||||
|
||||
|
||||
# form
|
||||
if hasattr(cls, 'form') and not issubclass(cls.form, BaseModelForm):
|
||||
|
||||
Reference in New Issue
Block a user