2
比方说,我提出以下查询:修改Django的QuerySet对象后,它已经创造了
showtimes = ShowTime.objects.filter(
start_date__lte=start,
end_date__gte=end,
movie__slug=movie.slug,
city=city,
visible=1)
现在我想有一个函数,它在queryset object
和过滤还基于其他一些属性的结果,是这样的:
def is_subtitled_3d(showtimes):
return (
showtimes.language == LANGUAGE_SUBTITLED and
showtimes.type_vip == None and
showtimes.type_3d == 1 and
showtimes.type_gtmax == None and
showtimes.type_xd == None)
将类似的东西,工作修改对象还是有不同的方式做到这一点?
这很好,正是我所需要的,谢谢包括文档链接。 – edu222 2013-02-20 20:53:31
顺便说一句,使用'is__null'比使用'== None'更好吗? – edu222 2013-02-20 20:58:05
@ edu222嗯,我不知道'= None'究竟做了什么,但是'isnull'会将你的查询翻译成'IS NULL'。 https://docs.djangoproject.com/en/dev/ref/models/querysets/#std:fieldlookup-isnull – dm03514 2013-02-20 21:01:41