Answer the question
In order to leave comments, you need to log in
Problem with email uniqueness check?
Hi all. I have a user registration form
forms.py:
from django import forms
from django.contrib.auth.models import User
class UserRegisrationForm(forms.ModelForm):
password = forms.CharField(label='Password', widget=forms.PasswordInput)
password2 = forms.CharField(label='Repeat Password', widget=forms.PasswordInput)
class Meta:
model = User
fields = ('username', 'first_name', 'email')
def clean_password2(self):
cd = self.cleaned_data
if cd['password'] != cd['password2']:
raise forms.ValidationError('Passwords don\'t match.')
return cd['password2']
def clean_email(self):
cd = self.cleaned_data
if User.objects.get(email=cd['email']):
raise forms.ValidationError('User with such mail exists. Use another.')
return cd['email']
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question