79 lines
2.1 KiB
Python
79 lines
2.1 KiB
Python
from django.contrib import admin
|
|
from django.contrib.auth.admin import UserAdmin
|
|
from unfold.admin import ModelAdmin
|
|
|
|
from .models import (
|
|
CustomUser,
|
|
StudentProfile,
|
|
InstructorProfile,
|
|
AdminProfile,
|
|
)
|
|
|
|
@admin.register(CustomUser)
|
|
class CustomUserAdmin(UserAdmin, ModelAdmin):
|
|
model = CustomUser
|
|
|
|
list_display = (
|
|
"email",
|
|
"username",
|
|
"is_active",
|
|
"is_staff",
|
|
)
|
|
|
|
list_filter = (
|
|
"is_active",
|
|
"is_staff",
|
|
"is_superuser",
|
|
)
|
|
|
|
search_fields = ("email","username")
|
|
ordering = ("email",)
|
|
|
|
fieldsets = (
|
|
(None, {"fields": ("email", "username", "password")}),
|
|
("Permissions", {"fields": ("is_active", "is_staff", "is_superuser", "groups")}),
|
|
("Important Dates", {"fields": ("last_login", "date_joined")}),
|
|
)
|
|
|
|
|
|
add_fieldsets = (
|
|
(None, {
|
|
"classes": ("wide",),
|
|
"fields": (
|
|
"email",
|
|
"username",
|
|
"password1",
|
|
"password2",
|
|
"is_staff",
|
|
"is_superuser",
|
|
),
|
|
}),
|
|
)
|
|
|
|
@admin.register(StudentProfile)
|
|
class StudentProfileAdmin(ModelAdmin):
|
|
list_display = ("user", "is_active")
|
|
search_fields = ("user__email", "user__username")
|
|
list_filter = ("is_active",)
|
|
|
|
@admin.register(InstructorProfile)
|
|
class InstructorProfileAdmin(ModelAdmin):
|
|
list_display = ("user", "expertise", "is_verified", "is_active")
|
|
search_fields = ("user__email", "user__username", "expertise")
|
|
list_filter = ("is_active", "is_verified")
|
|
|
|
actions = ["verify_instructor", "unverify_instructor"]
|
|
|
|
@admin.action(description="ยืนยันผู้สอน")
|
|
def verify_instructor(self, request, queryset):
|
|
queryset.update(is_verified=True)
|
|
|
|
@admin.action(description="ยกเลิกการยืนยันผู้สอน")
|
|
def unverify_instructor(self, request, queryset):
|
|
queryset.update(is_verified=False)
|
|
|
|
@admin.register(AdminProfile)
|
|
class AdminProfileAdmin(ModelAdmin):
|
|
list_display = ("user", "is_active", "is_super")
|
|
list_filter = ("is_active", "is_super")
|