This commit is contained in:
Midgard 2020-07-22 04:45:01 +02:00
parent 5e6e2120cf
commit cd3fc7956d
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 19 additions and 19 deletions

View file

@ -21,21 +21,21 @@ class Event(models.Model):
@property
def time_str(self):
return self.TIME_SLOTS[self.time]
return Event.TIME_SLOTS[self.time]
class EventRegistration(models.Model):
INTERESTED = "I"
ADMITTED = "A"
DENIED = "D"
REGISTRATION_STATE = (
(INTERESTED, "Interested"),
(ADMITTED, "Admitted"),
(DENIED, "Denied"),
)
REGISTRATION_STATE = {
INTERESTED: "Interested",
ADMITTED: "Admitted",
DENIED: "Denied",
}
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)
state = models.CharField(max_length=1, choices=REGISTRATION_STATE.items())
def __str__(self):
return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]"
@ -43,4 +43,4 @@ class EventRegistration(models.Model):
@property
def state_str(self):
return self.TIME_SLOTS[self.time]
return EventRegistration.REGISTRATION_STATE[self.state]

View file

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

View file

@ -24,9 +24,9 @@ def register(request, event_id):
if request.method == "POST":
event = get_object_or_404(Event, id=event_id)
# registration = Event.entry_set.create(
# state=EventRegistration.INTERESTED,
# event=event,
# user=CustomUser.objects.get(),
# )
event.eventregistration_set.create(
state=EventRegistration.INTERESTED,
event=event,
user=CustomUser.objects.get(),
)
return HttpResponseRedirect(reverse("events:index") + f"#{event.id}")