42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
from django.contrib import admin
|
|
from django.contrib.auth.admin import UserAdmin
|
|
from django.contrib.auth.forms import AdminPasswordChangeForm, UserChangeForm
|
|
from django.utils.translation import gettext_lazy as _
|
|
from .models import User
|
|
|
|
class CustomUserAdmin(UserAdmin):
|
|
model = User
|
|
change_password_form = AdminPasswordChangeForm
|
|
form = UserChangeForm
|
|
|
|
list_display = ("id", "first_name", "last_name", "phone", "role", "region", "is_active", "is_staff")
|
|
list_filter = ("role", "region", "is_staff", "is_superuser", "is_active")
|
|
search_fields = ("phone", "first_name", "last_name", "email")
|
|
ordering = ("phone",)
|
|
autocomplete_fields = ["groups"]
|
|
|
|
fieldsets = (
|
|
(None, {"fields": ("phone", "password")}),
|
|
(_("Personal info"), {"fields": ("first_name", "last_name", "email", "region")}),
|
|
(_("Permissions"), {
|
|
"fields": (
|
|
"is_active",
|
|
"is_staff",
|
|
"is_superuser",
|
|
"groups",
|
|
"user_permissions",
|
|
"role",
|
|
),
|
|
}),
|
|
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
|
|
)
|
|
|
|
add_fieldsets = (
|
|
(None, {
|
|
"classes": ("wide",),
|
|
"fields": ("phone", "password1", "password2", "role", "region", "is_active", "is_staff"),
|
|
}),
|
|
)
|
|
|
|
# Register the custom user
|
|
admin.site.register(User, CustomUserAdmin) |