Skip to content

Instantly share code, notes, and snippets.

@riklomas
Created August 6, 2010 15:01
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save riklomas/511440 to your computer and use it in GitHub Desktop.
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
# 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
Copy link

Hey Riklomas how can you see the UserAdmin on your current project admin since the UserAdmin belongs to auth application?

@riklomas
Copy link
Author

@julianmoji this snippet is from 2009(!) so not sure how valid it is any more!

@julianmoji
Copy link

julianmoji commented Nov 27, 2021

@riklomas I noticed it Haha so sorry I did not see the date thanks anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment