admin.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from django.contrib import admin
  2. from django.db.models import Avg
  3. from .models import TransactionEvent, TransactionGroup
  4. class TransactionGroupAdmin(admin.ModelAdmin):
  5. search_fields = ["transaction", "op", "project__organization__name"]
  6. list_display = ["transaction", "project", "op", "method", "avg_duration"]
  7. list_filter = ["created", "op", "method"]
  8. autocomplete_fields = ["project"]
  9. def avg_duration(self, obj):
  10. return obj.avg_duration
  11. def get_queryset(self, request):
  12. return (
  13. super()
  14. .get_queryset(request)
  15. .annotate(avg_duration=Avg("transactionevent__duration"))
  16. )
  17. # class SpanInline(admin.TabularInline):
  18. # model = Span
  19. # extra = 0
  20. # readonly_fields = [
  21. # "span_id",
  22. # "parent_span_id",
  23. # "op",
  24. # "description",
  25. # "start_timestamp",
  26. # "timestamp",
  27. # "tags",
  28. # "data",
  29. # ]
  30. # def has_add_permission(self, request, *args, **kwargs):
  31. # return False
  32. class TransactionEventAdmin(admin.ModelAdmin):
  33. search_fields = [
  34. "trace_id",
  35. "group__transaction",
  36. "group__project__organization__name",
  37. ]
  38. list_display = ["trace_id", "group", "timestamp", "duration"]
  39. # inlines = [SpanInline]
  40. can_delete = False
  41. admin.site.register(TransactionGroup, TransactionGroupAdmin)
  42. admin.site.register(TransactionEvent, TransactionEventAdmin)