Django按小时过滤 [英] Django filter by hour

查看:149
本文介绍了Django按小时过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个链接: http://code.djangoproject.com /attachment/ticket/8424/time_filters.diff ,并通过添加taht来更改我的django 1.2文件。

但现在,当我尝试写入Entry.objects时。过滤器(pub_date__hour = x) - 结果是以下错误:

I've found that link: http://code.djangoproject.com/attachment/ticket/8424/time_filters.diff and changed my django 1.2 files by adding taht what you can see there.
But now, when I'm trying to write Entry.objects.filter(pub_date__hour = x) - the result is following error:


字段无效查找:小时

Field has invalid lookup: hour

我该怎么办才能使其工作?

What should I do else, to make it work?

(抱歉我的英文)

推荐答案

Entry.objects.filter(pub_date__hour = x)

从django不支持1.2 - 只有年,月,日,周日。

is not supported as of django 1.2 - only year, month, day, week_day.

使用这样的东西:

Entry.objects.filter(pub_date__regex = '08:00')

Entry.objects.filter(pub_date__contains = '08:00')

这将给你所有的Entry对象与小时(多年)。

which will give you all Entry objects with the hour (over all years).

这篇关于Django按小时过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆