Fix 'helpers_required_total' metric
This commit is contained in:
parent
36cc1a5fec
commit
366f367a7d
|
@ -1,6 +1,5 @@
|
|||
from django.db import models
|
||||
from django.db.models import Count, Case, F, When, Sum
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.http import HttpResponse
|
||||
from shiftregister.app.models import Helper, Shift, ShiftRegistration, Message
|
||||
|
||||
|
@ -42,8 +41,11 @@ def metrics(request):
|
|||
"helpers_required_total",
|
||||
Shift.objects.filter(deleted=False)
|
||||
.annotate(
|
||||
real_required_helpers=Coalesce(
|
||||
F("required_helpers"), F("room__required_helpers")
|
||||
real_required_helpers=Case(
|
||||
When(
|
||||
required_helpers=0, then=F("room__required_helpers")
|
||||
),
|
||||
default=F("required_helpers"),
|
||||
)
|
||||
)
|
||||
.aggregate(sum=Sum("real_required_helpers"))["sum"],
|
||||
|
|
Loading…
Reference in New Issue