45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
from django import forms
|
|
from django.contrib import admin
|
|
from django.contrib.auth.models import Group
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
|
from django.contrib.auth.forms import (
|
|
AdminPasswordChangeForm
|
|
)
|
|
|
|
from account.forms import UserChangeForm, UserCreationForm
|
|
from account.models import MyUser
|
|
|
|
|
|
class UserAdmin(BaseUserAdmin):
|
|
# The forms to add and change user instances
|
|
form = UserChangeForm
|
|
add_form = UserCreationForm
|
|
change_password_form = AdminPasswordChangeForm
|
|
|
|
# The fields to be used in displaying the User model.
|
|
# These override the definitions on the base UserAdmin
|
|
# that reference specific fields on auth.User.
|
|
list_display = ('id', 'email', 'is_staff', 'is_superuser')
|
|
list_filter = ('is_staff', 'is_superuser',)
|
|
fieldsets = (
|
|
(None, {'fields': ('email', 'password')}),
|
|
('Personal info', {'fields': ('first_name', 'last_name')}),
|
|
('Permissions', {'fields': ('is_staff', 'is_superuser', 'user_permissions')}),
|
|
('Важные даты', {'fields': ('last_login', 'date_joined')})
|
|
)
|
|
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
|
|
# overrides get_fieldsets to use this attribute when creating a user.
|
|
add_fieldsets = (
|
|
(None, {
|
|
'classes': ('wide',),
|
|
'fields': ('email', 'password1', 'password2'),
|
|
}),
|
|
)
|
|
search_fields = ('email',)
|
|
ordering = ('email',)
|
|
filter_horizontal = ('user_permissions',)
|
|
|
|
|
|
admin.site.register(MyUser, UserAdmin)
|
|
admin.site.unregister(Group)
|