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()) return (self.start_at <= timezone.now()) and (not self.has_ended())
def registration_count(self): def registration_count(self):
return self.shiftregistration_set.filter( return (
state__in=[ self.reg_count
ShiftRegistration.RegState.REGISTERED, if hasattr(self, "reg_count")
ShiftRegistration.RegState.CHECKED_IN, else self.shiftregistration_set.filter(
] state__in=[
).count() ShiftRegistration.RegState.REGISTERED,
ShiftRegistration.RegState.CHECKED_IN,
]
).count()
)
class Helper(models.Model): class Helper(models.Model):

@ -9,7 +9,7 @@
<strong>Ort:</strong> {{ shift.room.name }}<br> <strong>Ort:</strong> {{ shift.room.name }}<br>
<strong>Beginn:</strong> {{ shift.start_at }}<br> <strong>Beginn:</strong> {{ shift.start_at }}<br>
<strong>Dauer:</strong> {{ shift.duration|duration }}<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>
<div class="buttons is-right"> <div class="buttons is-right">
<a class="button is-info is-small mr-0" href="{% url 'shift' shift.id %}">Details</a> <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>Beginn:</strong> {{ shift.start_at }}<br>
<strong>Dauer:</strong> {{ shift.duration|duration }}<br> <strong>Dauer:</strong> {{ shift.duration|duration }}<br>
<strong>Treffpunkt:</strong> {{ shift.room.meeting_location|linebreaksbr }}<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> </p>
{% if shift.room.description %} {% if shift.room.description %}
<div class="description"> <div class="description">

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

Loading…
Cancel
Save