﻿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
8620	ModelForm.Meta.exclude only excludes model fields, not form fields	levity	loic84	"If I have a ModelForm that inherits from another form, and I define exclude and/or fields, these only affect fields on the model. I cannot use them to exclude any non-model fields that I may have added to the ancestor form. E.g.:


{{{
class AForm(ModelForm):
  extra_non_model_field = forms.CharField()

class BForm(AForm):
  class Meta:
    model = Foo
    exclude = ('extra_non_model_field',) # this doesn't work, due to the way ModelFormMetaclass.__new__ is written
}}}


Sure that's a pathological example, but there are more sensible situations in which this is an issue. Seems to me it's more intuitive to expect the exclude/fields options to affect all fields, not just model fields.

A fix would be to add this at django/forms/models.py line 180:

{{{
        [declared_fields.pop(f) for f in declared_fields.keys() if f not in opts.fields or f in opts.exclude]
}}}




"	New feature	closed	Forms	dev	Normal	fixed		tom@… tom@… cody.somerville@… mmitar@… loic@…	Accepted	1	0	0	0	0	0
