我正在为希望能够改变营业时间的客户建立一个网站 为他的每个不同的商店。 Django是否存在针对此类问题的现有解决方案?
答案 0 :(得分:12)
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)
答案 1 :(得分:1)
有一个可重用的应用程序:django-openinghours。该应用程序的代码基础乍一看似乎有点尘土飞扬(没有PEP8,camelCase,..),但是django-openinghours带有一系列有用的功能,可靠且在现场测试多年。