Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.
Please advise, thank you.
Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.
Please advise, thank you.
What we did. It isn't a "complete" solution, but it does much of what you're looking for.
class UserForm( forms.ModelForm ):
class Meta:
model= User
exclude= ('email',)
username = forms.EmailField(max_length=64,
help_text = "The person's email address.")
def clean_email( self ):
email= self.cleaned_data['username']
return email
class UserAdmin( admin.ModelAdmin ):
form= UserForm
list_display = ( 'email', 'first_name', 'last_name', 'is_staff' )
list_filter = ( 'is_staff', )
search_fields = ( 'email', )
admin.site.unregister( User )
admin.site.register( User, UserAdmin )
you can also find an interesting discussion on this topic at the below link :
S.Lott's solution has an error in the subclassing of UserAdmin which breaks changing passwords from the admin. Here's a fixed version. I've also added the imports needed.
from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
class UserForm(forms.ModelForm):
class Meta:
model = User
exclude = ('email',)
username = forms.EmailField(max_length=64,
help_text="The person's email address.")
def clean_email(self):
email = self.cleaned_data['username']
return email
class UserAdmin(UserAdmin):
form = UserForm
list_display = ('email', 'first_name', 'last_name', 'is_staff')
list_filter = ('is_staff',)
search_fields = ('email',)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)