In Django, 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
):
class MyUserChangeForm(UserChangeForm):
class Meta(UserChangeForm.Meta):
fields = ('first_name', 'last_name', 'email')
But this does not work as it adds/keeps also an username
field in the resulting form. This field was declared explicitly in UserChangeForm
. Even adding username
to exclude
attribute does not help.
Is there some proper way to exclude it and I am missing something? Is this a bug? Is there some workaround?