Prototypes of Schedule and Slot model
This commit is contained in:
parent
17b1363ee4
commit
36da9c4dd0
4 changed files with 47 additions and 0 deletions
0
api_v1/schedule/__init__.py
Normal file
0
api_v1/schedule/__init__.py
Normal file
13
api_v1/schedule/model.py
Normal file
13
api_v1/schedule/model.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
from api_v1.profile.model import Profile
|
||||||
|
|
||||||
|
|
||||||
|
class Schedule(models.Model):
|
||||||
|
schedule_id = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
||||||
|
|
||||||
|
profile = models.ForeignKey(Profile, on_delete=models.DO_NOTHING, null=False)
|
||||||
|
|
||||||
|
slots = models.ManyToOneRel()
|
0
api_v1/slot/__init__.py
Normal file
0
api_v1/slot/__init__.py
Normal file
34
api_v1/slot/model.py
Normal file
34
api_v1/slot/model.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
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)
|
Loading…
Reference in a new issue