今天发生的Django过滤器事件

今天发生的Django过滤器事件,第1张

今天发生的Django过滤器事件

您将需要两个不同的

datetime
阈值-
today_start
today_end

from datetime import datetime, timedelta, timetoday = datetime.now().date()tomorrow = today + timedelta(1)today_start = datetime.combine(today, time())today_end = datetime.combine(tomorrow, time())

今天发生的所有事情都必须在 之前 开始

today_end
之后 结束
today_start
,因此:

class EventManager(models.Manager):    def bookings_today(self, location_id):        # Construction of today_end / today_start as above, omitted for brevity        return self.filter(location=location_id, start__lte=today_end, end__gte=today_start)

(PS叫

DateTimeField
(非
DateField
foo_date
会令人误解,请考虑-
start
end
…)



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5646041.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存