2
0
Fork 0

Fix registration count without ruining performance

This commit is contained in:
Luca 2023-05-10 23:33:42 +02:00
parent 01ac707ab7
commit 1f0a1b3fbf
4 changed files with 13 additions and 9 deletions

View File

@ -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):

View File

@ -9,7 +9,7 @@
<strong>Ort:</strong> {{ shift.room.name }}<br>
<strong>Beginn:</strong> {{ shift.start_at }}<br>
<strong>Dauer:</strong> {{ shift.duration|duration }}<br>
<strong>Belegung:</strong> {{ shift.reg_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }}
<strong>Belegung:</strong> {{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }}
</div>
<div class="buttons is-right">
<a class="button is-info is-small mr-0" href="{% url 'shift' shift.id %}">Details</a>

View File

@ -21,7 +21,7 @@
<strong>Beginn:</strong> {{ shift.start_at }}<br>
<strong>Dauer:</strong> {{ shift.duration|duration }}<br>
<strong>Treffpunkt:</strong> {{ shift.room.meeting_location|linebreaksbr }}<br>
<strong>Belegung:</strong> {{ shift.reg_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }}
<strong>Belegung:</strong> {{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }}
</p>
{% if shift.room.description %}
<div class="description">

View File

@ -6,7 +6,7 @@
<strong>Ort:</strong> {{ shift.room.name }}<br>
<strong>Beginn:</strong> {{ shift.start_at }}<br>
<strong>Dauer:</strong> {{ shift.duration }}<br>
<strong>Belegung:</strong> {{ shift.reg_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }}
<strong>Belegung:</strong> {{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }}
</div>
<div class="is-flex is-justify-content-end">
<a class="button is-info is-small" href="{% url 'team:shift' shift.id %}">Details</a>