您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

今天发生的Django过滤器事件

今天发生的Django过滤器事件

您将需要两个不同的datetime阈值-today_starttoday_end

from datetime import datetime, timedelta, time

today = 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(非DateFieldfoo_date会令人误解,请考虑-startend…)

Go 2022/1/1 18:46:50 有382人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶