admin.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.contrib import admin
  2. from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
  3. from django.utils.translation import gettext_lazy as _
  4. from .models import User, UserProjectAlert
  5. class UserAdmin(BaseUserAdmin):
  6. ordering = ("email",)
  7. list_display = ("email", "name")
  8. fieldsets = (
  9. (None, {"fields": ("email", "password")}),
  10. (_("Personal info"), {"fields": ("name", "subscribe_by_default")},),
  11. (
  12. _("Permissions"),
  13. {
  14. "fields": (
  15. "is_active",
  16. "is_staff",
  17. "is_superuser",
  18. "groups",
  19. "user_permissions",
  20. ),
  21. },
  22. ),
  23. (_("Important dates"), {"fields": ("last_login",)}),
  24. )
  25. add_fieldsets = (
  26. (None, {"classes": ("wide",), "fields": ("email", "password1", "password2"),}),
  27. )
  28. search_fields = ("email", "name")
  29. class UserProjectAlertAdmin(admin.ModelAdmin):
  30. list_display = ("user", "project", "status")
  31. list_filter = ("status",)
  32. search_fields = ("project__name", "user__email")
  33. raw_id_fields = (
  34. "user",
  35. "project",
  36. )
  37. admin.site.register(User, UserAdmin)
  38. admin.site.register(UserProjectAlert, UserProjectAlertAdmin)