如何获取给定时间段内的数据

时间:2014-12-30 16:27:38

标签: python django datetime django-models

我尝试执行以下查询,为我提供此期间的锦标赛:

sart_date = 2014-05-01 00:00:00
end_date = 2014-05-31 23:59:59

以下是我用于此目的的代码:

start_date = datetime.datetime.strptime(request.GET['start_date'], '%Y-%m-%d %H:%M:%S')
    end_date = datetime.datetime.strptime(request.GET['end_date'], '%Y-%m-%d %H:%M:%S')
    upcoming = Tournament.objects.filter(Q(started__gte=start_date), Q(ended__lte=end_date),
                                         Q(championship_id=championship_id))
    print upcoming.query

打印应用程序时,我会遇到以下情况:

.....WHERE (`tournaments_tournament`.`started` >= 2014-04-30 21:00:00  AND `tournaments_tournament`.`ended` <= 2014-05-31 20:59:59  AND `tournaments_tournament`.`championship_id` = 11 )....

以下是字段在模型中的显示方式:

started = models.DateTimeField (_('start date and time'))
ended = models.DateTimeField (_('end date and time'), null = True, blank=True)

有没有人知道为何如此获得并且有办法解决这个问题?

0 个答案:

没有答案