Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ModelAdmin.fields wasn't able to refer to fields only on a custom form

Regressed in r11737 which used get_field instead of opts.get_field and ignoring
fields not found.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12279 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4d81874f9d65ecb002d252381a1e108b85f377e4 1 parent dbad025
Brian Rosner brosner authored
7 django/contrib/admin/validation.py
View
@@ -211,7 +211,12 @@ def validate_base(cls, model):
# validation of such things.
continue
check_formfield(cls, model, opts, 'fields', field)
- f = get_field(cls, model, opts, 'fields', field)
+ try:
+ f = opts.get_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.
+ continue
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 "
14 tests/regressiontests/admin_validation/models.py
View
@@ -215,4 +215,18 @@ class AuthorsBooks(models.Model):
# the validation will fail.
>>> validate(BookAdmin, Book)
+# Regression for ensuring ModelAdmin.fields can contain non-model fields
+# that broke with r11737
+
+>>> class SongForm(forms.ModelForm):
+... extra_data = forms.CharField()
+... class Meta:
+... model = Song
+
+>>> class FieldsOnFormOnlyAdmin(admin.ModelAdmin):
+... form = SongForm
+... fields = ['title', 'extra_data']
+
+>>> validate(FieldsOnFormOnlyAdmin, Song)
+
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.