I created a registration form and two custom user types; students and parents. The registration works perfect for both users. The problem is when I go to django admin and view my users, the password for students is in a hashed algorithim, while for parent users the password field says "Invalid password format or unknown hashing algorithm". I'm unsure where the problem stems from, but assume it is from my parent form inheriting the register form. Any help will be appreciated, thanks!
forms.py
class ParentSignUpForm(RegisterForm):
first_name = forms.CharField(widget=forms.TextInput(attrs={'class' : 'form-control', 'placeholder' : 'Parent first name', 'id' : 'parent-first', 'required' : 'true'}))
last_name = forms.CharField(widget=forms.TextInput(attrs={'class' : 'form-control', 'placeholder' : 'Parent last name', 'id' : 'parent-last', 'required' : 'true'}))
child_first_name = forms.CharField(widget=forms.TextInput(attrs={'class' : 'form-control', 'placeholder' : "Child's first name", 'id' : 'child-first', 'required' : 'true'}))
def clean_password2(self):
# Check that the two password entries match
password = self.cleaned_data.get("password")
password2 = self.cleaned_data.get("password2")
if password and password2 and password != password2:
raise forms.ValidationError("Passwords don't match")
return password2
def save(self, commit=True):
user = super(ParentSignUpForm, self).save(commit=False)
user.set_password = self.cleaned_data["password"]
user.parent = True
if commit:
user.save()
return user
class Meta:
# what model you're using
model = User
# what fields from that model you want
fields = ['email', 'password', 'password2']
views.py
def parent_sign_up(request):
if request.method == 'POST':
form = ParentSignUpForm(request.POST)
if form.is_valid():
user = form.save()
return redirect('home')
else:
form = ParentSignUpForm()
form = ParentSignUpForm()
context = {'form' : form}
return render(request, 'accounts/parent_sign_up.html', context)