models.py 1014 B

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