diff --git a/events/models.py b/events/models.py index 4668b6f..754ebd8 100644 --- a/events/models.py +++ b/events/models.py @@ -19,19 +19,28 @@ class Event(models.Model): return f"{self.date} {self.TIME_SLOTS[self.time]}" - @property def time_str(self): return Event.TIME_SLOTS[self.time] + def count_with_status(self, status): + return self.eventregistration_set.filter(state=status).count() + + + def count_interested(self): + return self.count_with_status(EventRegistration.INTERESTED) + + + def count_admitted(self): + return self.count_with_status(EventRegistration.ADMITTED) + + class EventRegistration(models.Model): INTERESTED = "I" ADMITTED = "A" - DENIED = "D" REGISTRATION_STATE = { INTERESTED: "Interested", ADMITTED: "Admitted", - DENIED: "Denied", } event = models.ForeignKey(Event, on_delete=models.CASCADE) user = models.ForeignKey(CustomUser, on_delete=models.CASCADE) @@ -41,6 +50,5 @@ class EventRegistration(models.Model): return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]" - @property def state_str(self): return EventRegistration.REGISTRATION_STATE[self.state] diff --git a/events/templates/events/index.html b/events/templates/events/index.html index 94de5b6..ea02fed 100644 --- a/events/templates/events/index.html +++ b/events/templates/events/index.html @@ -3,13 +3,12 @@ {% block content %}