[英]How to filter more than one property in Google AppEngine? (python)
我在使用使用多個過濾器的查詢時遇到問題(我在使用NDB而不是DB):
...
foo = something.query(something.a==5, something.b<8, something.c<3).order(something.b).fetch(1)
...
我收到此錯誤:
Only one inequality filter per query is supported.
我可以使用以下方法解決此問題:
...
foo = something.query(something.a==5, something.b<8).order(something.b).fetch()
#loop through each one of those rows and add those who have foo.c<3 to some array
但是這種解決方案並不是很好。 有人有更好的主意嗎?
謝謝
我遇到了一個相關的問題,我使用了ComputedProperty來解決它。 例如,您可能有一個ComputedProperty(lambda self:self.b <8和self.c <3),然后僅查詢該ComputedProperty是否為真。
您需要使用query.AND或query.OR :
qry = Article.query(query.AND(Article.tags == 'python',
query.OR(Article.tags.IN(['ruby', 'jruby']),
query.AND(Article.tags == 'php',
Article.tags != 'perl'))))
這是我解決的方法:
foo = something.query(ndb.query.AND(something.a==5, something.b<8, ndb.query.OR(something.c==1, something.c==2)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.