2👍
✅
It’s not a bad idea to have a look at a class you subclass. password1
and password2
fields are defined in form directly, not in the model. So exclude
and fields
will have no effect on them. Just make your own ModelForm
as @MatthewSchinckel suggests.
5👍
You can just remove the password2 field in the init of the form like so:
class MyUserCreationForm(UserCreationForm):
def __init__(self, *args, **kargs):
super(MyUserCreationForm, self).__init__(*args, **kargs)
del self.fields['password2']
1👍
Why not just use a ModelForm
, and exclude the fields you don’t want? That seems like it would be a simpler solution.
- [Django]-Django ImportError: cannot import name list_route
- [Django]-Django logging: Cannot create logs per day
- [Django]-Redirect to "next" after python-social-auth login
1👍
think that would give the idea…
class RegistrationForm(UserCreationForm):
email = forms.EmailField(required=True)
#first_name = forms.CharField(required=True)
#last_name = forms.CharField(required=True)
username = forms.CharField (required=True)
class Meta:
model = User
fields = ('first_name','last_name','username','email', 'password1', 'password2')
def __init__ (self, *args, **kwargs):
super(RegistrationForm,self).__init__(*args, **kwargs)
#remove what you like...
self.fields.pop ('first_name')
self.fields.pop ('last_name')
self.fields.pop ('password1')
self.fields.pop ('password2')
👤Sarp
- [Django]-Prevent emails from Python from being flagged as spam
- [Django]-Python: Element order in dictionary
- [Django]-Wagtail: Can i use the API for fetching read-only drafts of pages for review?
Source:stackexchange.com