Django的营业时间 [英] Business Opening hours in Django

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

问题描述

我想添加诊所的营业时间,并且已经研究了这个中,但这对我来说不合适.因为这假设您在所有工作日都具有相同的时间设置,而在特殊的日子具有相同的时间设置.鉴于我希望各天有不同的开放时间.此外,我希望一天有不止1个条目.例如,周日的诊所从上午8:30-下午12:00营业,并从下午4:30-晚上10点再次营业.

I want to add Business hours for a clinic and I've looked into this Any existing solution to implement "opening hours" in Django but it's not right for me. Because this one assumes you'll have same set of hours for all the weekdays and same set of hours for special days. Whereas, I want to have different opening hours for individual days. Moreover, I want to have more than 1 entry for an individual day. For instance, a clinic on Sunday runs from 8:30 am - 12:00 pm and opens again from 4:30 pm - 10 pm.

我希望能够从管理面板添加它,类似于Yelp

I want to be able to add this from the admin panel, similar to Yelp

推荐答案

恕我直言,链接中的解决方案几乎可以满足您的要求.只需对其进行一些自定义即可:

IMHO the solution from the link is doing almost exactly what you want. Just customize it a bit:

WEEKDAYS = [
  (1, _("Monday")),
  (2, _("Tuesday")),
  (3, _("Wednesday")),
  (4, _("Thursday")),
  (5, _("Friday")),
  (6, _("Saturday")),
  (7, _("Sunday")),
]

class OpeningHours(models.Model):

    weekday = models.IntegerField(choices=WEEKDAYS)
    from_hour = models.TimeField()
    to_hour = models.TimeField()

    class Meta:
        ordering = ('weekday', 'from_hour')
        unique_together = ('weekday', 'from_hour', 'to_hour')

    def __unicode__(self):
        return u'%s: %s - %s' % (self.get_weekday_display(),
                                 self.from_hour, self.to_hour)

这篇关于Django的营业时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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