30 lines
929 B
Python
30 lines
929 B
Python
# -*- encoding: utf-8 -*-
|
|
|
|
from django.contrib import admin
|
|
|
|
from .models import User, Department
|
|
|
|
|
|
class UserAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ["uuid", "forename", "surname", "email", "get_department_title", "icon", "is_staff", "is_superuser", "is_active"]
|
|
list_filter = ["department__title", "is_staff", "is_superuser", "is_active"]
|
|
ordering = ["department__title"]
|
|
|
|
@admin.display(description="Department", ordering="department__title")
|
|
def get_department_title(self, obj):
|
|
return obj.department.title if obj.department else None
|
|
|
|
|
|
class DepartmentAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ["uuid", "title", "colour", "backgroundcolour", "order", "get_user_count"]
|
|
|
|
@admin.display(description="Users")
|
|
def get_user_count(self, obj):
|
|
return User.objects.filter(department=obj).count()
|
|
|
|
|
|
admin.site.register(User, UserAdmin)
|
|
admin.site.register(Department, DepartmentAdmin)
|