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
@@ -4,6 +4,14 @@
<h1 class="mb-4">Exam Collections</h1>
<form method="get" class="mb-3" id="archive-filter-form">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="showArchived" name="show_archived" value="1" onchange="this.form.submit()"
{% if request.GET.show_archived %}checked{% endif %}>
<label class="form-check-label" for="showArchived">Show archived collections</label>
</div>
</form>
{% if object_list %}
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3">
{% for collection in object_list %}
+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)),