Start events frontend
This commit is contained in:
parent
7872e4f5b2
commit
313366413d
8 changed files with 93 additions and 14 deletions
|
@ -1,3 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
from .models import Event, EventRegistration
|
||||||
|
|
||||||
|
admin.site.register(Event)
|
||||||
|
admin.site.register(EventRegistration)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.0.8 on 2020-07-21 21:36
|
# Generated by Django 3.0.8 on 2020-07-22 01:36
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
@ -18,7 +18,8 @@ class Migration(migrations.Migration):
|
||||||
name='Event',
|
name='Event',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('date', models.DateTimeField()),
|
('date', models.DateField()),
|
||||||
|
('time', models.IntegerField(choices=[(0, 'Voormiddag'), (1, 'Namiddag'), (2, 'Avond')])),
|
||||||
('capacity', models.IntegerField()),
|
('capacity', models.IntegerField()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -26,7 +27,7 @@ class Migration(migrations.Migration):
|
||||||
name='EventRegistration',
|
name='EventRegistration',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('shirt_size', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)),
|
('state', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)),
|
||||||
('event_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')),
|
('event_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')),
|
||||||
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
],
|
],
|
||||||
|
|
|
@ -4,16 +4,32 @@ from users.models import CustomUser
|
||||||
|
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
date = models.DateTimeField()
|
MORNING, AFTERNOON, EVENING = range(3)
|
||||||
capacity = models.IntegerField()
|
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]}"
|
||||||
|
|
||||||
|
|
||||||
class EventRegistration(models.Model):
|
class EventRegistration(models.Model):
|
||||||
|
INTERESTED = "I"
|
||||||
|
ADMITTED = "A"
|
||||||
|
DENIED = "D"
|
||||||
REGISTRATION_STATE = (
|
REGISTRATION_STATE = (
|
||||||
('I', 'Interested'),
|
(INTERESTED, "Interested"),
|
||||||
('A', 'Admitted'),
|
(ADMITTED, "Admitted"),
|
||||||
('D', 'Denied'),
|
(DENIED, "Denied"),
|
||||||
)
|
)
|
||||||
event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
|
event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||||
user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
|
user_id = 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)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"[{self.state}] {self.user.username}"
|
||||||
|
|
10
events/templates/events/detail.html
Normal file
10
events/templates/events/detail.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>{{ event.date }} (maximum {{ event.capacity }} mensen)</h2>
|
||||||
|
<ul>
|
||||||
|
{% for regi in event.registration %}
|
||||||
|
{{ regi.user.username }}: {{regi.state}}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
19
events/templates/events/index.html
Normal file
19
events/templates/events/index.html
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<ul>
|
||||||
|
{% for event in events %}
|
||||||
|
<li>{{ event.date }} {{ event.time }} (maximum {{ event.capacity }} mensen)
|
||||||
|
<ul>
|
||||||
|
<form action="{% url 'events:register' event.id %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% for regi in event.registration %}
|
||||||
|
{{ regi.user.username }}: {{regi.state}}
|
||||||
|
{% endfor %}
|
||||||
|
<li><input type="submit" value="Ik wil komen"></li>
|
||||||
|
</form>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
|
@ -2,6 +2,8 @@ from django.urls import path
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
|
app_name = "events"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path("", views.index, name="index"),
|
||||||
|
path("<int:event_id>/", views.register, name="register"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,8 +1,24 @@
|
||||||
from django.shortcuts import render
|
from django.http import HttpResponseRedirect
|
||||||
|
from django.shortcuts import render, get_object_or_404
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.urls import reverse
|
||||||
|
import datetime
|
||||||
|
|
||||||
# Create your views here.
|
from .models import Event, EventRegistration, CustomUser
|
||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("Hello, world. You're at the polls index.")
|
events = Event.objects.filter(date__gte=timezone.now().date()).order_by("date")[:20]
|
||||||
|
return render(request, "events/index.html", {"events": events})
|
||||||
|
|
||||||
|
|
||||||
|
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(),
|
||||||
|
# )
|
||||||
|
return HttpResponseRedirect(reverse("events:index", args=(event.id,)))
|
||||||
|
|
12
templates/base.html
Normal file
12
templates/base.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width"/>
|
||||||
|
<title>Zeus WPI Kelderregistratiesysteem™</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Zeus WPI Kelderregistratiesysteem™</h1>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue