From 988888df834dbc0b279084d15efc679279262b51 Mon Sep 17 00:00:00 2001 From: Ben Dichter Date: Sat, 28 Dec 2024 19:45:37 -0500 Subject: [PATCH] Update dandiapi/api/views/dandiset.py Co-authored-by: Jacob Nesbitt --- dandiapi/api/views/dandiset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dandiapi/api/views/dandiset.py b/dandiapi/api/views/dandiset.py index efd0b0240..1cf6e0650 100644 --- a/dandiapi/api/views/dandiset.py +++ b/dandiapi/api/views/dandiset.py @@ -108,7 +108,8 @@ def filter_queryset(self, request, queryset, view): return queryset.order_by(ordering) if ordering.endswith('stars'): queryset = queryset.annotate(stars_count=Count('stars')) - return queryset.order_by(f"{'-' if ordering.startswith('-') else ''}stars_count") + prefix = '-' if ordering.startswith('-') else '' + return queryset.order_by(f"{prefix}stars_count") return queryset