In Django, I am trying to get a new look from the ModelForm form where I Want to delete some areas (or just for some fields, and be more accurate). Of course, we must do it clearly (with base form django.contrib.auth.forms ):
class MyUserChangeForm (UserChangeForm): Class Meta (UserChangeForm. ): Field = ('first_name', 'last_name', 'email') but it does not work because it also adds a username as a result This field was clearly declared in UserChangeForm . Even adding usernames to by adding attribute does not help.
Is there any proper way to get it out and I'm missing something? Is this a bug? Is there some solution?
Try this:
class MyUserChangeForm (userChangeForm): def __init __ (self, * args, ** kwargs): Super (MyUserChangeForm, itself) .__ init __ (* args, ** kwargs) self.fields.pop ('username') square meta (UserChangeForm.Meta): field = ('First_name', 'last_name', 'email') It dynamically removes a field from the form when it is created.
Comments
Post a Comment