Fix display of time of day

This commit is contained in:
Midgard 2020-07-22 04:24:01 +02:00
parent 53a7e23b4f
commit 32b443cc81
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 13 additions and 2 deletions

View file

@ -14,10 +14,16 @@ class Event(models.Model):
time = models.IntegerField(choices=TIME_SLOTS.items(), default=MORNING) time = models.IntegerField(choices=TIME_SLOTS.items(), default=MORNING)
capacity = models.IntegerField(default=6) capacity = models.IntegerField(default=6)
def __str__(self): def __str__(self):
return f"{self.date} {self.TIME_SLOTS[self.time]}" return f"{self.date} {self.TIME_SLOTS[self.time]}"
@property
def time_str(self):
return self.TIME_SLOTS[self.time]
class EventRegistration(models.Model): class EventRegistration(models.Model):
INTERESTED = "I" INTERESTED = "I"
ADMITTED = "A" ADMITTED = "A"
@ -33,3 +39,8 @@ class EventRegistration(models.Model):
def __str__(self): def __str__(self):
return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]" return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]"
@property
def state_str(self):
return self.TIME_SLOTS[self.time]

View file

@ -3,12 +3,12 @@
{% block content %} {% block content %}
<ul> <ul>
{% for event in events %} {% for event in events %}
<li>{{ event.date }} {{ event.time }} (maximum {{ event.capacity }} mensen) <li>{{ event.date }} {{ event.time_str }} (maximum {{ event.capacity }} mensen)
<ul> <ul>
<form action="{% url 'events:register' event.id %}" method="post"> <form action="{% url 'events:register' event.id %}" method="post">
{% csrf_token %} {% csrf_token %}
{% for regi in event.registration %} {% for regi in event.registration %}
{{ regi.user.username }}: {{regi.state}} {{ regi.user.username }}: {{regi.state_str}}
{% endfor %} {% endfor %}
<li><input type="submit" value="Ik wil komen"></li> <li><input type="submit" value="Ik wil komen"></li>
</form> </form>