Created
August 19, 2009 23:03
-
-
Save johnboxall/170691 to your computer and use it in GitHub Desktop.
email_address_usernames.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# admin.py - get the User form working the Django Admin w/ email usernames. | |
from django.contrib.auth.forms import UserChangeForm | |
from django.contrib.auth.admin import UserAdmin | |
class EmailUserChangeForm(UserChangeForm): | |
username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^[\w@.]+$', | |
help_text = _("Required. 30 characters or fewer. Valid email addresses only.")) | |
class EmailUserAdmin(UAdmin): | |
form = EmailUserChangeForm | |
# ... register the admin ... | |
# views.py - email addresses can be long so relax the login form max_length. | |
from django.contrib.auth.forms import AuthenticationForm | |
AuthenticationForm.base_fields["username"].max_length = 60 | |
AuthenticationForm.base_fields["username"].widget.attrs["maxlength"] = 60 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment