This method will not make the email field unique at the database level, but worth a try.
Use custom validator :
from django.core.exceptions import ValidationError from django.contrib.auth.models import User def validate_email_unique(value): exists = User.objects.filter(username=value) if exists: raise ValidationError("Email address %s already exits, must be unique" % value)
Then in forms.py:
from django.contrib.auth.models import User from django.forms import ModelForm from main.validators import validate_email_unique class UserForm(ModelForm):
user476955
source share