Fix count annotations in exam collection to use distinct values for accurate user counts
This commit is contained in:
+4
-4
@@ -192,8 +192,8 @@ def exam_collection_exams_partial(request, collection_id: int, exam_type: str):
|
|||||||
related_qs = (
|
related_qs = (
|
||||||
ExamModel.objects.filter(pk__in=pks)
|
ExamModel.objects.filter(pk__in=pks)
|
||||||
.annotate(
|
.annotate(
|
||||||
valid_cid_users_count=Count("valid_cid_users"),
|
valid_cid_users_count=Count("valid_cid_users", distinct=True),
|
||||||
valid_user_users_count=Count("valid_user_users"),
|
valid_user_users_count=Count("valid_user_users", distinct=True),
|
||||||
)
|
)
|
||||||
.prefetch_related("author")
|
.prefetch_related("author")
|
||||||
.order_by("name")
|
.order_by("name")
|
||||||
@@ -1925,8 +1925,8 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
# Annotate counts for template usage so `.count()` is not called per-object.
|
# Annotate counts for template usage so `.count()` is not called per-object.
|
||||||
# Use unfiltered counts to match the per-exam `exam_overview` counts.
|
# Use unfiltered counts to match the per-exam `exam_overview` counts.
|
||||||
exam_list = exam_list.annotate(
|
exam_list = exam_list.annotate(
|
||||||
valid_cid_users_count=Count("valid_cid_users"),
|
valid_cid_users_count=Count("valid_cid_users", distinct=True),
|
||||||
valid_user_users_count=Count("valid_user_users"),
|
valid_user_users_count=Count("valid_user_users", distinct=True),
|
||||||
).select_related("examcollection").prefetch_related("author")
|
).select_related("examcollection").prefetch_related("author")
|
||||||
|
|
||||||
if not all:
|
if not all:
|
||||||
|
|||||||
Reference in New Issue
Block a user