import uuid from django.core.exceptions import ValidationError from django.db import models def validate_weekday(value: int): if value < 0 or value > 6: raise ValidationError("Weekday must be between 0 (Mo) and 6 (Su)") class Slot(models.Model): slot_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) start_time = models.TimeField() end_time = models.TimeField() duration = models.DurationField() start_weekday = models.SmallIntegerField(validators=[validate_weekday]) end_weekday = models.SmallIntegerField(validators=[validate_weekday]) def __str__(self): days = [ "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su" ] return "[{}] {} - [{}] {}".format(days[self.start_weekday], self.start_time, days[self.end_weekday], self.end_time)