40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from django.contrib import admin
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
|
from django.contrib.auth.admin import GroupAdmin as BaseGroupAdmin
|
|
from django.contrib.auth.models import User, Group
|
|
|
|
from unfold.forms import AdminPasswordChangeForm, UserChangeForm, UserCreationForm
|
|
from unfold.admin import ModelAdmin
|
|
|
|
|
|
# Unregister default and re-register User/Group with Unfold admin
|
|
try:
|
|
admin.site.unregister(Group)
|
|
admin.site.unregister(User)
|
|
except admin.sites.NotRegistered:
|
|
pass
|
|
|
|
|
|
@admin.register(User)
|
|
class UserAdmin(BaseUserAdmin, ModelAdmin):
|
|
form = UserChangeForm
|
|
add_form = UserCreationForm
|
|
change_password_form = AdminPasswordChangeForm
|
|
list_filter_sheet = True
|
|
compressed_fields = True
|
|
warn_unsaved_form = True
|
|
|
|
def get_readonly_fields(self, request, obj=None):
|
|
readonly = list(super().get_readonly_fields(request, obj))
|
|
if obj:
|
|
readonly.extend(["email"])
|
|
return tuple(dict.fromkeys(readonly))
|
|
|
|
|
|
@admin.register(Group)
|
|
class GroupAdmin(BaseGroupAdmin, ModelAdmin):
|
|
pass
|
|
|
|
|
|
# No index override; use Unfold dashboard sections
|