Skip to content

Commit 0c60f19

Browse files
committed
Add recording count to recording tag admin
1 parent 36bac54 commit 0c60f19

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

bats_ai/core/admin/recording_tag.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.contrib import admin
2+
from django.db.models import Count
23

34
from bats_ai.core.models import RecordingTag
45

@@ -9,5 +10,16 @@ class RecordingTagAdmin(admin.ModelAdmin):
910
'id',
1011
'user',
1112
'text',
13+
'recording_count',
1214
)
1315
search_fields = ('id', 'user', 'text')
16+
17+
def get_queryset(self, request):
18+
qs = super().get_queryset(request)
19+
return qs.annotate(_recording_count=Count("recording"))
20+
21+
def recording_count(self, obj):
22+
return obj._recording_count
23+
24+
recording_count.short_description = "Number of recordings"
25+
recording_count.admin_order_field = "_recording_count"

0 commit comments

Comments
 (0)