kers/events/models.py
Midgard 84a46989ac
Don't show list of people, scrap "denied"
When the event is full, people can just stay "interested".
2020-07-22 05:33:33 +02:00

54 lines
1.4 KiB
Python

from django.db import models
from users.models import CustomUser
class Event(models.Model):
MORNING, AFTERNOON, EVENING = range(3)
TIME_SLOTS = {
MORNING: "Voormiddag",
AFTERNOON: "Namiddag",
EVENING: "Avond",
}
date = models.DateField()
time = models.IntegerField(choices=TIME_SLOTS.items(), default=MORNING)
capacity = models.IntegerField(default=6)
def __str__(self):
return f"{self.date} {self.TIME_SLOTS[self.time]}"
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"
REGISTRATION_STATE = {
INTERESTED: "Interested",
ADMITTED: "Admitted",
}
event = models.ForeignKey(Event, on_delete=models.CASCADE)
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
state = models.CharField(max_length=1, choices=REGISTRATION_STATE.items())
def __str__(self):
return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]"
def state_str(self):
return EventRegistration.REGISTRATION_STATE[self.state]