Skip to content

Commit

Permalink
Merge pull request #1986 from dandi/version-status-query
Browse files Browse the repository at this point in the history
Fix N query problem with VersionStatusFilter
  • Loading branch information
jjnesbitt authored Jul 24, 2024
2 parents 38f2d75 + 5597576 commit 794d130
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dandiapi/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,17 @@ class VersionStatusFilter(admin.SimpleListFilter):
title = 'status'
parameter_name = 'status'

def lookups(self, request, model_admin):
qs = model_admin.get_queryset(request)
for status in qs.values_list('status', flat=True).distinct():
count = qs.filter(status=status).count()
if count:
yield (status, f'{status} ({count})')
def lookups(self, *args, **kwargs):
# The queryset for VersionAdmin contains unnecessary data,
# so just use base queryset from Version.objects
qs = (
Version.objects.values_list('status')
.distinct()
.annotate(total=Count('status'))
.order_by()
)
for status, count in qs:
yield (status, f'{status} ({count})')

def queryset(self, request, queryset):
status = self.value()
Expand Down

0 comments on commit 794d130

Please sign in to comment.