Created
August 6, 2010 15:01
-
-
Save riklomas/511440 to your computer and use it in GitHub Desktop.
How to add a field to the Django Admin Add User form using UserCreationForm. Add this to a admin.py and alter to whatever fields you'd like
This file contains hidden or 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
# How to add a field to the Django Admin Add User form | |
# using UserCreationForm. Add this to a admin.py and alter | |
# to whatever fields you'd like | |
from django.contrib.auth.forms import UserCreationForm | |
from django.contrib.auth.models import User | |
from django.contrib.auth.admin import UserAdmin | |
from django import forms | |
from django.utils.translation import ugettext_lazy as _ | |
from django.contrib import admin | |
class UserCreationFormExtended(UserCreationForm): | |
def __init__(self, *args, **kwargs): | |
super(UserCreationFormExtended, self).__init__(*args, **kwargs) | |
self.fields['email'] = forms.EmailField(label=_("E-mail"), max_length=75) | |
UserAdmin.add_form = UserCreationFormExtended | |
UserAdmin.add_fieldsets = ( | |
(None, { | |
'classes': ('wide',), | |
'fields': ('email', 'username', 'password1', 'password2',) | |
}), | |
) | |
admin.site.unregister(User) | |
admin.site.register(User, UserAdmin) |
@julianmoji this snippet is from 2009(!) so not sure how valid it is any more!
@riklomas I noticed it Haha so sorry I did not see the date thanks anyway
for an updated version : https://gist.github.com/fchabouis/8f92abc043ca450120d7bcfa50b34bdc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Riklomas how can you see the UserAdmin on your current project admin since the UserAdmin belongs to auth application?