subDesTagesMitExtraKaese před 1 rokem
rodič
revize
503861c94c
4 změnil soubory, kde provedl 85 přidání a 3 odebrání
  1. 12 1
      zitap/admin.py
  2. 45 0
      zitap/migrations/0001_initial.py
  3. 22 1
      zitap/models.py
  4. 6 1
      zitap/views.py

+ 12 - 1
zitap/admin.py

@@ -1,3 +1,14 @@
 from django.contrib import admin
+from .models import Event, Date, Participant
 
-# Register your models here.
+@admin.register(Event)
+class EventAdmin(admin.ModelAdmin):
+    list_display = ('name', 'url', 'created_at')
+
+@admin.register(Date)
+class DateAdmin(admin.ModelAdmin):
+    list_display = ('event', 'date')
+
+@admin.register(Participant)
+class ParticipantAdmin(admin.ModelAdmin):
+    list_display = ('event', 'name', 'slots')

+ 45 - 0
zitap/migrations/0001_initial.py

@@ -0,0 +1,45 @@
+# Generated by Django 4.1.2 on 2022-12-17 10:43
+
+import datetime
+from django.db import migrations, models
+import django.db.models.deletion
+import zitap.models
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Event',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('url', models.CharField(default=zitap.models.generate_random_url, max_length=6, unique=True)),
+                ('name', models.CharField(max_length=255)),
+                ('slot_interval', models.DurationField(default=datetime.timedelta(seconds=900))),
+                ('created_at', models.DateTimeField(auto_now_add=True)),
+            ],
+        ),
+        migrations.CreateModel(
+            name='Participant',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(max_length=255)),
+                ('pw_hash', models.CharField(max_length=255)),
+                ('slots', models.BinaryField()),
+                ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='zitap.event')),
+            ],
+        ),
+        migrations.CreateModel(
+            name='Date',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('date', models.DateField()),
+                ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='zitap.event')),
+            ],
+        ),
+    ]

+ 22 - 1
zitap/models.py

@@ -1,3 +1,24 @@
+from datetime import timedelta
+import random
 from django.db import models
 
-# Create your models here.
+def generate_random_url():
+    # a-z, A-Z, 0-9, -, _
+    characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
+    return ''.join(random.choice(characters) for i in range(6))
+
+class Event(models.Model):
+    url = models.CharField(max_length=6, default=generate_random_url, unique=True)
+    name = models.CharField(max_length=255)
+    slot_interval = models.DurationField(default=timedelta(minutes=15))
+    created_at = models.DateTimeField(auto_now_add=True)
+
+class Date(models.Model):
+    event = models.ForeignKey(Event, on_delete=models.CASCADE)
+    date = models.DateField()
+
+class Participant(models.Model):
+    event = models.ForeignKey(Event, on_delete=models.CASCADE)
+    name = models.CharField(max_length=255)
+    pw_hash = models.CharField(max_length=255)
+    slots = models.BinaryField()

+ 6 - 1
zitap/views.py

@@ -2,6 +2,7 @@ from django.http import HttpResponseRedirect
 from django.shortcuts import render
 
 from .forms import CreateEventForm
+from .models import Event
 
 def index(request):
     return render(request, 'zitap/index.html')
@@ -15,7 +16,11 @@ def create_event(request):
         if form.is_valid():
             data = form.cleaned_data
             print(data)
-            #return HttpResponseRedirect('/edit-event')
+            event = Event.objects.create(name=data['event_name'])
+            for date in data['event_date']:
+                event.date_set.create(date=date)
+            event.save()
+            return HttpResponseRedirect(f'/{event.url}')
     else:
         form = CreateEventForm()
     return render(request, 'zitap/create-event.html', {'form': form})