diff --git a/shiftregister/app/models.py b/shiftregister/app/models.py index 580234b..e6039e5 100644 --- a/shiftregister/app/models.py +++ b/shiftregister/app/models.py @@ -37,16 +37,14 @@ class Shift(models.Model): def with_reg_count(): return Shift.objects.annotate( reg_count=Count( - Case( - When( - shiftregistration__state__in=[ - ShiftRegistration.RegState.REGISTERED, - ShiftRegistration.RegState.CHECKED_IN, - ], - then=1, - ), - output_field=models.IntegerField(), - ) + "shiftregistration", + distinct=True, + filter=Q( + shiftregistration__state__in=( + ShiftRegistration.RegState.REGISTERED, + ShiftRegistration.RegState.CHECKED_IN, + ) + ), ) ) diff --git a/shiftregister/signage/views.py b/shiftregister/signage/views.py index f2ed8f2..29d60bc 100644 --- a/shiftregister/signage/views.py +++ b/shiftregister/signage/views.py @@ -70,7 +70,7 @@ def team_dashboard(request): When(required_helpers=0, then=F("room__required_helpers")), default=F("required_helpers"), ), - fallbackassignment_count=Count("fallbackassignment"), + fallbackassignment_count=Count("fallbackassignment", distinct=True), ) .filter( deleted=False,