Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
email_address_usernames.py
# 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
You can’t perform that action at this time.