Add admin stuff for custom users
This commit is contained in:
parent
e6068af1b7
commit
33af7f13d1
2 changed files with 43 additions and 0 deletions
28
users/admin.py
Normal file
28
users/admin.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
|
||||
from .forms import CustomUserCreationForm, CustomUserChangeForm
|
||||
from .models import CustomUser
|
||||
|
||||
|
||||
class CustomUserAdmin(UserAdmin):
|
||||
add_form = CustomUserCreationForm
|
||||
form = CustomUserChangeForm
|
||||
model = CustomUser
|
||||
list_display = ('username', 'is_staff', 'is_superuser')
|
||||
list_filter = ('username', 'is_staff')
|
||||
fieldsets = (
|
||||
(None, {'fields': ('username', 'password')}),
|
||||
('Permissions', {'fields': ('is_staff', 'is_superuser')}),
|
||||
)
|
||||
add_fieldsets = (
|
||||
(None, {
|
||||
'classes': ('wide',),
|
||||
'fields': ('username', 'password1', 'password2', 'is_staff')}
|
||||
),
|
||||
)
|
||||
search_fields = ('username',)
|
||||
ordering = ('username',)
|
||||
|
||||
|
||||
admin.site.register(CustomUser, CustomUserAdmin)
|
15
users/forms.py
Normal file
15
users/forms.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
||||
|
||||
from .models import CustomUser
|
||||
|
||||
|
||||
class CustomUserCreationForm(UserCreationForm):
|
||||
class Meta(UserCreationForm):
|
||||
model = CustomUser
|
||||
fields = ('username',)
|
||||
|
||||
|
||||
class CustomUserChangeForm(UserChangeForm):
|
||||
class Meta:
|
||||
model = CustomUser
|
||||
fields = ('username',)
|
Loading…
Reference in a new issue