admin.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from django.contrib import admin
  2. from import_export import resources
  3. from import_export.admin import ImportExportModelAdmin
  4. from .models import Project, ProjectKey, UserProjectAlert
  5. class ProjectKeyResource(resources.ModelResource):
  6. class Meta:
  7. model = ProjectKey
  8. skip_unchanged = True
  9. fields = ("project", "label", "public_key")
  10. import_id_fields = (
  11. "project",
  12. "public_key",
  13. )
  14. class ProjectKeyInline(admin.StackedInline):
  15. model = ProjectKey
  16. extra = 0
  17. readonly_fields = ("dsn",)
  18. class ProjectResource(resources.ModelResource):
  19. class Meta:
  20. model = Project
  21. skip_unchanged = True
  22. fields = ("id", "created", "slug", "name", "organization", "platform")
  23. class ProjectAdmin(ImportExportModelAdmin):
  24. search_fields = ("name",)
  25. list_display = ("name", "organization")
  26. raw_id_fields = ("organization",)
  27. inlines = [ProjectKeyInline]
  28. resource_class = ProjectResource
  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(Project, ProjectAdmin)
  38. admin.site.register(UserProjectAlert, UserProjectAlertAdmin)