I'm trying to modelize business hours for a week of a company. Here is my attempt:
class Company(models.Model):
name = models.CharField(max_length=100)
logo = models.FileField(upload_to='company_logos')
mon_start = models.TimeField()
mon_end = models.TimeField()
tue_start = models.TimeField()
tue_end = models.TimeField()
wed_start = models.TimeField()
wed_end = models.TimeField()
thu_start = models.TimeField()
thu_end = models.TimeField()
fri_start = models.TimeField()
fri_end = models.TimeField()
sat_start = models.TimeField()
sat_end = models.TimeField()
sun_start = models.TimeField(blank=True)
sun_end = models.TimeField(blank=True)
Does this seem correct ?
Isn't there a more dynamic way to define it ?
Can I easily validate each day (on a form) ?
From @lyapun suggestion, an acceptable solution for me would be:
WEEKDAYS = [
(1, _("Monday")),
(2, _("Tuesday")),
(3, _("Wednesday")),
(4, _("Thursday")),
(5, _("Friday")),
(6, _("Saturday")),
(7, _("Sunday")),
]
class Company(models.Model):
name = models.CharField(
max_length=100
)
logo = models.FileField(
upload_to='company_logos'
)
class OpeningHours(models.Model):
store = models.ForeignKey(
Company
)
weekday = models.IntegerField(
choices=WEEKDAYS,
unique=True
)
from_hour = models.TimeField()
to_hour = models.TimeField()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With