您将需要两个不同的
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…)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)