I'm making a website for a client who wants to be able to change then opening hours for each of his different stores. Is there an existing solution for this type of problem with Django ?
What do you mean? Seems pretty simple. Adjust according to your weekday order. And if you like, add validation. But people should be smart enough to not need validation for that sort of stuff.
HOUR_OF_DAY_24 = [(i,i) for i in range(1,25)]
WEEKDAYS = [
(1, _("Monday")),
(2, _("Tuesday")),
(3, _("Wednesday")),
(4, _("Thursday")),
(5, _("Friday")),
(6, _("Saturday")),
(7, _("Sunday")),
]
class OpeningHours(models.Model):
store = models.ForeignKey("StoreModel")
weekday_from = models.PositiveSmallIntegerField(choices=WEEKDAYS, unique=True)
weekday_to = models.PositiveSmallIntegerField(choices=WEEKDAYS)
from_hour = models.PositiveSmallIntegerField(choices=HOUR_OF_DAY_24)
to_hour = models.PositiveSmallIntegerField(choices=HOUR_OF_DAY_24)
def get_weekday_from_display(self):
return WEEKDAYS[self.weekday_from]
def get_weekday_to_display(self):
return WEEKDAYS[self.weekday_to]
class SpecialDays(models.Model):
holiday_date = models.DateField()
closed = models.BooleanField(default=True)
from_hour = models.PositiveSmallIntegerField(choices=HOUR_OF_DAY_24, null=True, blank=True)
to_hour = models.PositiveSmallIntegerField(choices=HOUR_OF_DAY_24, null=True, blank=True)
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