Override model field attributes from a ModelForm?

10 views
Skip to first unread message

Storn White

unread,
Oct 3, 2013, 4:27:29 PM10/3/13
to django...@googlegroups.com
Hi,

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!
  
Reply all
Reply to author
Forward
0 new messages