Skip to content

Instantly share code, notes, and snippets.



Created Apr 16, 2009
What would you like to do?
Customizing User list view and edit form in Django
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from forms import UserChangeForm
class UserAdmin(BaseUserAdmin):
list_display = ('username', 'last_name', 'first_name', 'is_superuser', 'is_staff')
list_filter = ('groups', 'is_staff', 'is_superuser')
ordering = ('last_name', 'first_name')
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('first_name', 'last_name')}),
('Permissions', {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}),
('Important dates', {'fields': ('last_login', 'date_joined')}),
('Groups', {'fields': ('groups',)}),
form = UserChangeForm, UserAdmin)
from django.contrib.auth.models import User
from django import forms
class UserChangeForm(forms.ModelForm):
class Meta:
model = User
def save(self, commit=True):
user = super(UserChangeForm, self).save(commit=False)
user.username = self.cleaned_data['email']
if commit:
return user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment