admin.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from django.utils.translation import gettext_lazy as _
  2. from django.contrib import admin
  3. from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
  4. from access.models import User
  5. from django.contrib.auth.models import Group
  6. admin.site.unregister(Group)
  7. @admin.register(User)
  8. class UserAdmin(BaseUserAdmin):
  9. search_fields = ["email", "name"]
  10. readonly_fields = ["id", "uuid", "created_at", "updated_at"]
  11. list_display = [
  12. "email",
  13. "name",
  14. "gender",
  15. "birthdate",
  16. "avatar",
  17. "is_active",
  18. "is_admin",
  19. "is_staff",
  20. "created_at",
  21. ]
  22. list_filter = [
  23. "is_active",
  24. "is_admin",
  25. "is_staff",
  26. "created_at",
  27. "updated_at",
  28. "gender",
  29. ]
  30. filter_horizontal = []
  31. date_hierarchy = "created_at"
  32. ordering = ["-created_at"]
  33. add_fieldsets = (
  34. (
  35. _("Сведения"),
  36. {
  37. "fields": ["name", "email", "birthdate", "gender", "avatar"]
  38. },
  39. ),
  40. (
  41. _("Доступ"),
  42. {"fields": ["is_active", "is_admin", "is_staff"]},
  43. ),
  44. )
  45. fieldsets = (
  46. (
  47. _("Сведения"),
  48. {
  49. "fields": ["id", "uuid", "name", "email", "birthdate", "gender", "avatar"]
  50. },
  51. ),
  52. (
  53. _("Доступ"),
  54. {"fields": ["is_active", "is_admin","is_staff", "password"]},
  55. ),
  56. (_("Даты"), {"fields": ["created_at", "updated_at"]}),
  57. )
  58. class Media:
  59. pass