from datetime import timedelta import random from django.db import models from django.contrib.auth.models import User from django.utils.translation import gettext as _ 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) start_time = models.TimeField(default='09:00') end_time = models.TimeField(default='20:00') class Date(models.Model): event = models.ForeignKey(Event, on_delete=models.CASCADE) date = models.DateField() class Participant(models.Model): name = models.CharField(max_length=255) event = models.ForeignKey(Event, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True) slots = models.BinaryField()