From 1f0a1b3fbf85b308d1faeb27b91e27a0008f7d84 Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 10 May 2023 23:33:42 +0200 Subject: [PATCH] Fix registration count without ruining performance --- shiftregister/app/models.py | 16 ++++++++++------ .../app/templates/partials/shift_listitem.html | 2 +- shiftregister/app/templates/shift.html | 2 +- .../team/templates/partials/shift_box.html | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/shiftregister/app/models.py b/shiftregister/app/models.py index 2dc4def..ea3931c 100644 --- a/shiftregister/app/models.py +++ b/shiftregister/app/models.py @@ -57,12 +57,16 @@ class Shift(models.Model): return (self.start_at <= timezone.now()) and (not self.has_ended()) def registration_count(self): - return self.shiftregistration_set.filter( - state__in=[ - ShiftRegistration.RegState.REGISTERED, - ShiftRegistration.RegState.CHECKED_IN, - ] - ).count() + return ( + self.reg_count + if hasattr(self, "reg_count") + else self.shiftregistration_set.filter( + state__in=[ + ShiftRegistration.RegState.REGISTERED, + ShiftRegistration.RegState.CHECKED_IN, + ] + ).count() + ) class Helper(models.Model): diff --git a/shiftregister/app/templates/partials/shift_listitem.html b/shiftregister/app/templates/partials/shift_listitem.html index 0f495bd..2cc710f 100644 --- a/shiftregister/app/templates/partials/shift_listitem.html +++ b/shiftregister/app/templates/partials/shift_listitem.html @@ -9,7 +9,7 @@ Ort: {{ shift.room.name }}
Beginn: {{ shift.start_at }}
Dauer: {{ shift.duration|duration }}
- Belegung: {{ shift.reg_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }} + Belegung: {{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }}
Details diff --git a/shiftregister/app/templates/shift.html b/shiftregister/app/templates/shift.html index 6f687b2..3598c19 100644 --- a/shiftregister/app/templates/shift.html +++ b/shiftregister/app/templates/shift.html @@ -21,7 +21,7 @@ Beginn: {{ shift.start_at }}
Dauer: {{ shift.duration|duration }}
Treffpunkt: {{ shift.room.meeting_location|linebreaksbr }}
- Belegung: {{ shift.reg_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }} + Belegung: {{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }}

{% if shift.room.description %}
diff --git a/shiftregister/team/templates/partials/shift_box.html b/shiftregister/team/templates/partials/shift_box.html index 24d309d..822b034 100644 --- a/shiftregister/team/templates/partials/shift_box.html +++ b/shiftregister/team/templates/partials/shift_box.html @@ -6,7 +6,7 @@ Ort: {{ shift.room.name }}
Beginn: {{ shift.start_at }}
Dauer: {{ shift.duration }}
- Belegung: {{ shift.reg_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }} + Belegung: {{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }}