Fix knop
This commit is contained in:
parent
5e6e2120cf
commit
cd3fc7956d
3 changed files with 19 additions and 19 deletions
|
@ -21,21 +21,21 @@ class Event(models.Model):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def time_str(self):
|
def time_str(self):
|
||||||
return self.TIME_SLOTS[self.time]
|
return Event.TIME_SLOTS[self.time]
|
||||||
|
|
||||||
|
|
||||||
class EventRegistration(models.Model):
|
class EventRegistration(models.Model):
|
||||||
INTERESTED = "I"
|
INTERESTED = "I"
|
||||||
ADMITTED = "A"
|
ADMITTED = "A"
|
||||||
DENIED = "D"
|
DENIED = "D"
|
||||||
REGISTRATION_STATE = (
|
REGISTRATION_STATE = {
|
||||||
(INTERESTED, "Interested"),
|
INTERESTED: "Interested",
|
||||||
(ADMITTED, "Admitted"),
|
ADMITTED: "Admitted",
|
||||||
(DENIED, "Denied"),
|
DENIED: "Denied",
|
||||||
)
|
}
|
||||||
event = models.ForeignKey(Event, on_delete=models.CASCADE)
|
event = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||||
user = models.ForeignKey(CustomUser, 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):
|
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}]"
|
||||||
|
@ -43,4 +43,4 @@ class EventRegistration(models.Model):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_str(self):
|
def state_str(self):
|
||||||
return self.TIME_SLOTS[self.time]
|
return EventRegistration.REGISTRATION_STATE[self.state]
|
||||||
|
|
|
@ -4,15 +4,15 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% for event in events %}
|
{% for event in events %}
|
||||||
<li id="{{event.id}}">{{ event.date }} {{ event.time_str }} (maximum {{ event.capacity }} mensen)
|
<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 %}
|
{% csrf_token %}
|
||||||
{% for regi in event.registration %}
|
{% for regi in event.eventregistration_set.all %}
|
||||||
{{ regi.user.username }}: {{regi.state_str}}
|
<li>{{ regi.user.username }}: {{regi.state_str}}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li><input type="submit" value="Ik wil komen"></li>
|
<li><input type="submit" value="Ik wil komen"></li>
|
||||||
</form>
|
</ul>
|
||||||
</ul>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -24,9 +24,9 @@ def register(request, event_id):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
event = get_object_or_404(Event, id=event_id)
|
event = get_object_or_404(Event, id=event_id)
|
||||||
|
|
||||||
# registration = Event.entry_set.create(
|
event.eventregistration_set.create(
|
||||||
# state=EventRegistration.INTERESTED,
|
state=EventRegistration.INTERESTED,
|
||||||
# event=event,
|
event=event,
|
||||||
# user=CustomUser.objects.get(),
|
user=CustomUser.objects.get(),
|
||||||
# )
|
)
|
||||||
return HttpResponseRedirect(reverse("events:index") + f"#{event.id}")
|
return HttpResponseRedirect(reverse("events:index") + f"#{event.id}")
|
||||||
|
|
Loading…
Reference in a new issue