Add functionality to filter exam collections by archived status

This commit is contained in:
Ross
2025-11-11 21:07:25 +00:00
parent 6be39ab69d
commit c8375a28fa
2 changed files with 16 additions and 1 deletions
+8 -1
View File
@@ -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)),