﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17428	Admin formfield validation uses form model instead of registered model	David Bennett	dante87	"The admin [https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/validation.py#L383 check_formfield] validation function is checking for fields in the form's model (if specified) by default.

Meanwhile, the ModelAdmin [https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/options.py#L459 get_form] method always overrides the form's model with the registered model.

So, doing something like this generates a validation error saying that field2 is missing from the form:

{{{
class Base(models.Model):
    field1 = models.CharField(max_length=10)

class Sub(Base):
    field2 = models.CharField(max_length=10)

class BaseForm(forms.ModelForm):
    class Meta:
        model = Base

class BaseAdmin(admin.ModelAdmin):
    form = BaseForm

class SubAdmin(BaseAdmin):
    fields = ('field1', 'field2')

admin.site.register(Sub, SubAdmin)
}}}

It would appear to me that fields shouldn't be validated against the form's model as it isn't actually used.

I've managed to work around it with the following:

{{{
class SubAdmin(BaseAdmin):
    form = forms.ModelForm
    fields = ('field1', 'field2')

    def __init__(self, model, admin_site):
        self.form = BaseForm
        super(SubAdmin, self).__init__(model, admin_site)
}}}

This causes check_formfield to use the registered model's fields for validation, but then swaps in the original form on init.
"	Bug	closed	contrib.admin	1.3	Normal	wontfix		Per Rosengren	Ready for checkin	1	0	0	0	1	0
