实施“营业时间"的任何现有解决方案在 Django [英] Any existing solution to implement "opening hours" in Django

查看:18
本文介绍了实施“营业时间"的任何现有解决方案在 Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为希望能够更改营业时间的客户制作网站对于他的每个不同的商店.Django 是否有针对此类问题的现有解决方案?

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)

这篇关于实施“营业时间"的任何现有解决方案在 Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆