Add functionality to filter exam collections by archived status
This commit is contained in:
+8
-1
@@ -5342,8 +5342,15 @@ class ExamCollectionList(ListView):
|
||||
|
||||
def get_queryset(self):
|
||||
"""Annotate exam counts per collection and prefetch authors to avoid N+1 queries in templates."""
|
||||
# allow toggling whether archived collections are included via ?show_archived=1
|
||||
show_archived = self.request.GET.get("show_archived")
|
||||
|
||||
base_qs = ExamCollection.objects.all()
|
||||
if not show_archived:
|
||||
base_qs = base_qs.filter(archive=False)
|
||||
|
||||
qs = (
|
||||
ExamCollection.objects.all()
|
||||
base_qs
|
||||
.annotate(
|
||||
anatomy_count=Count("anatomy_exams", filter=Q(anatomy_exams__archive=False)),
|
||||
longs_count=Count("longs_exams", filter=Q(longs_exams__archive=False)),
|
||||
|
||||
Reference in New Issue
Block a user