models.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. from datetime import timedelta
  2. import random
  3. from django.db import models
  4. from django.contrib.auth.models import User
  5. from django.utils.translation import gettext as _
  6. def generate_random_url():
  7. # a-z, A-Z, 0-9, -, _
  8. characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
  9. return ''.join(random.choice(characters) for i in range(6))
  10. class Event(models.Model):
  11. url = models.CharField(max_length=6, default=generate_random_url, unique=True)
  12. name = models.CharField(max_length=255)
  13. slot_interval = models.DurationField(default=timedelta(minutes=15))
  14. created_at = models.DateTimeField(auto_now_add=True)
  15. start_time = models.TimeField(default='09:00')
  16. end_time = models.TimeField(default='20:00')
  17. class Date(models.Model):
  18. event = models.ForeignKey(Event, on_delete=models.CASCADE)
  19. date = models.DateField()
  20. class Participant(models.Model):
  21. name = models.CharField(max_length=255)
  22. event = models.ForeignKey(Event, on_delete=models.CASCADE)
  23. user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
  24. slots = models.BinaryField()