我正在尝试使用Django 1.6按Performance
小时过滤start_time
。在控制台中我看到:
>>> Performance.objects.first().start_time
datetime.datetime(2014, 4, 6, 11, 0, tzinfo=<UTC>)
>>> Performance.objects.first().start_time.hour
11
但是,来自https://docs.djangoproject.com/en/1.6/ref/models/querysets/#hour的文档:
>>> Performance.objects.filter(start_time__hour=11)
[]
如何按小时过滤?与此(目前尚未回答)问题非常相似:Django ORM: filter by hour range。
来自models.py
:
class Performance(models.Model):
start_time = models.DateTimeField(db_index=True)
end_time = models.DateTimeField(default=None, blank=True, null=True)
...
答案 0 :(得分:1)