mixr-api/api_v1/slot/model.py

35 lines
951 B
Python
Raw Normal View History

2024-02-29 00:06:16 +01:00
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)