Excluding a declared field in ModelForm in form’s subclass
|Reported by:||Mitar||Owned by:||nobody|
|Cc:||mmitar@…, cody.somerville@…||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I am trying to derive (subclass) a new form from ModelForm form where I would like to remove some fields (or to have only some fields, to be more correct). Of course obvious way would be to do (base form is from django.contrib.auth.forms, this is just an example):
class MyUserChangeForm(UserChangeForm): class Meta(UserChangeForm.Meta): fields = ('first_name', 'last_name', 'email')
But this does not work as it adds/keeps also the username field in the resulting form. This field was declared explicitly in UserChangeForm. Even adding username to exclude attribute does not help.
It seems this is a bug.
The workaround is to remove the field in form constructor from
Change History (13)
comment:4 Changed 6 years ago by
|Triage Stage:||Unreviewed → Design decision needed|