meh*_*kar 2 google-app-engine djangoappengine app-engine-ndb
我需要构建一个带有重复属性的逻辑查询,但无法使其工作.我有一个主题列表对象.
topics = [u'string1', u'string2', ...]
Run Code Online (Sandbox Code Playgroud)
我有一个查询对象:
videos = Video.query()
videos.count()
=> 19
Run Code Online (Sandbox Code Playgroud)
主题是重复的字符串属性
class Video
topics = ndb.StringProperty(repeated=True)
Run Code Online (Sandbox Code Playgroud)
我想要返回有主题string1OR的视频string2.我之前也不知道列表对象的长度,或者我可以用逻辑运算符来构建查询.
我尝试这样做就像文档建议的那样
videos.filter( Video.topics.IN([topics]) )
Run Code Online (Sandbox Code Playgroud)
但是会抛出IN期望字符串而不是列表对象的错误.
我该怎么做呢?
看起来topics已经是一个清单了.所以你需要在没有其他列表的情况下传递它:
videos.filter( Video.topics.IN(topics) )
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3803 次 |
| 最近记录: |