我不确定是否正确地用AND
和OR
构建查询。当我查询到只匹配标签时,我会得到一些匹配的视频。但是,当我尝试第二个查询时(以确保视频与其本身无关),查询将返回所有视频。
Update:我希望返回至少有一个与video
相同的标签的视频,但是返回的列表中不包含video
。基本上是一个related_videos特性。
from solveforx.lib.moonshots import Video
from google.appengine.ext import ndb
video = Video.query().get()
tags = video.tags or []
for tag in tags:
print Video.query(Video.tags == tag).count() # returns 1
print "-------"
print Video.query(Video.tags == tag and Video.key != video.key) # returns total videos - 1
print "========"
# also tried this
# print Video.query(Video.tags == tag, ndb.AND(Video.key != moonshot.key)).count() # returns 0
# print Video.query(ndb.AND(ndb.AND(Video.tags == tag), ndb.AND(Video.key != video.key) )).count()
看看文献资料在这个问题上,但不确定运营商是如何工作的。
发布于 2013-03-26 14:46:49
AND
至少有两个参数。你应该这样做:
Video.query(ndb.AND(Video.tags == tag, Video.key != video.key))
从您发布的链接中,您可以看到更多关于如何将其与ndb.OR
结合的示例。
发布于 2013-03-26 14:41:26
这样做是有效的:
for tag in tags:
Video.query(Video.tags == tag, Video.key != video.key)
https://stackoverflow.com/questions/15638912
复制相似问题