admin.py 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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
  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. admin.site.register(Project, ProjectAdmin)