My custom user model requires unique email addresses, which are the users' identifiers.
My user registration modelform works great. If a user tries to register with an email that is already in the system, the form fails to validate and the 'unique' invalid message is displayed back to the user.
I am trying to create an authentication modelform based on the same user model. When I try to authenticate a registered user, the email field throws the unique validation error. How can I overwrite this property? I've tried:
class MyUserModel(AbstractBaseUser):
"""
Custom User Model requires unique email address.
"""
# email field
email = models.EmailField(
unique=True,
error_messages={
'invalid': "You must enter a valid email address.",
'unique': "Your email address is already in our system!"
}
)
class MyAuthForm(forms.ModelForm):
"""
Form for authenticating users.
"""
def __init__(self, *args, **kwargs):
super(MyAuthForm, self).__init__(*args, **kwargs)
self.Meta.model.email.unique = True
I've tried a few variations on this with no luck. Any ideas?
Thanks!