Trying to create user using django-formtools.
forms.py
class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm):
model = User
fields = ('username', 'password1', 'password2')
class CustomProfileCreateForm(forms.ModelForm):
class Meta:
model = User
fields = ('name', 'email')
views.py
class SignupWizard(SessionWizardView):
template_name = "user/registration.html"
form_list = [CustomUserCreationForm, CustomProfileCreateForm]
instance = None
def get_form_instance(self, step):
if self.instance is None:
self.instance = User()
return self.instance
def done(self, form_list, **kwargs):
self.instance.save()
return render(self.request, 'done.html', {
'form_data': [form.cleaned_data for form in form_list],
})
All are ok except password. Password is not set. How to save form correctly
Password for users are set with the set_password method of the user models.
The password1 and password2 fields are not fields of the User model, but fields of the UserCreationForm. You should call the save method of your CustomUserCreationForm instead of the save method of your user.
To understand better how all this work, I suggest you take a look at the UserCreationForm.save method.