# -*- 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", "icon", "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)
