Add functionality to filter exam collections by archived status
This commit is contained in:
@@ -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
@@ -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