Fix registration count without ruining performance

pull/1/head
Luca 2 years ago
parent 01ac707ab7
commit 1f0a1b3fbf

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

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

@ -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">

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

Loading…
Cancel
Save