From e600b8eb91d0f217c7c3c7c102d487aef97995bc Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 4 Jan 2026 12:55:53 +0000 Subject: [PATCH] Fix count annotations in exam collection to use distinct values for accurate user counts --- generic/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/generic/views.py b/generic/views.py index 5dcee7df..6443c97a 100644 --- a/generic/views.py +++ b/generic/views.py @@ -192,8 +192,8 @@ def exam_collection_exams_partial(request, collection_id: int, exam_type: str): related_qs = ( ExamModel.objects.filter(pk__in=pks) .annotate( - valid_cid_users_count=Count("valid_cid_users"), - valid_user_users_count=Count("valid_user_users"), + valid_cid_users_count=Count("valid_cid_users", distinct=True), + valid_user_users_count=Count("valid_user_users", distinct=True), ) .prefetch_related("author") .order_by("name") @@ -1925,8 +1925,8 @@ class ExamViews(View, LoginRequiredMixin): # Annotate counts for template usage so `.count()` is not called per-object. # Use unfiltered counts to match the per-exam `exam_overview` counts. exam_list = exam_list.annotate( - valid_cid_users_count=Count("valid_cid_users"), - valid_user_users_count=Count("valid_user_users"), + valid_cid_users_count=Count("valid_cid_users", distinct=True), + valid_user_users_count=Count("valid_user_users", distinct=True), ).select_related("examcollection").prefetch_related("author") if not all: