2
0
Fork 0

Fix 'helpers_required_total' metric

This commit is contained in:
Luca 2023-05-08 18:11:29 +02:00
parent 36cc1a5fec
commit 366f367a7d
1 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,5 @@
from django.db import models from django.db import models
from django.db.models import Count, Case, F, When, Sum from django.db.models import Count, Case, F, When, Sum
from django.db.models.functions import Coalesce
from django.http import HttpResponse from django.http import HttpResponse
from shiftregister.app.models import Helper, Shift, ShiftRegistration, Message from shiftregister.app.models import Helper, Shift, ShiftRegistration, Message
@ -42,8 +41,11 @@ def metrics(request):
"helpers_required_total", "helpers_required_total",
Shift.objects.filter(deleted=False) Shift.objects.filter(deleted=False)
.annotate( .annotate(
real_required_helpers=Coalesce( real_required_helpers=Case(
F("required_helpers"), F("room__required_helpers") When(
required_helpers=0, then=F("room__required_helpers")
),
default=F("required_helpers"),
) )
) )
.aggregate(sum=Sum("real_required_helpers"))["sum"], .aggregate(sum=Sum("real_required_helpers"))["sum"],