-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.py
31 lines (26 loc) · 897 Bytes
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# admin.py
from django.contrib import admin
from .models import User
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
list_display = ['username', 'first_name', 'last_name', 'account_created', 'account_updated']
search_fields = ['username', 'first_name', 'last_name']
readonly_fields = ['account_created', 'account_updated']
fieldsets = (
(None, {
'fields': ('username', 'password')
}),
('Personal Info', {
'fields': ('first_name', 'last_name')
}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('username', 'first_name', 'last_name', 'password'),
}),
)
def save_model(self, request, obj, form, change):
if not change:
obj.set_password(form.cleaned_data['password'])
super().save_model(request, obj, form, change)