简体   繁体   English

如何在Google AppEngine中过滤多个属性? (蟒蛇)

[英]How to filter more than one property in Google AppEngine? (python)

I have a problem using queries that are using more than one filter (I am using NDB instead DB): 我在使用使用多个过滤器的查询时遇到问题(我在使用NDB而不是DB):

...
foo = something.query(something.a==5, something.b<8, something.c<3).order(something.b).fetch(1)
...

I am getting this error: 我收到此错误:

Only one inequality filter per query is supported.

I could solve this problem by using something like this: 我可以使用以下方法解决此问题:

...
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

but that solution is not really great. 但是这种解决方案并不是很好。 Does anybody have some better idea? 有人有更好的主意吗?

Thanks 谢谢

I had a related problem, and I used a ComputedProperty to solve it. 我遇到了一个相关的问题,我使用了ComputedProperty来解决它。 Eg, you could have a ComputedProperty(lambda self: self.b < 8 and self.c < 3) and then just query for whether that ComputedProperty is true. 例如,您可能有一个ComputedProperty(lambda self:self.b <8和self.c <3),然后仅查询该ComputedProperty是否为真。

You need to use the query.AND or query.OR : 您需要使用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.

相关问题 Python:如何将多个参数传递给属性 getter? - Python: How to pass more than one argument to the property getter? 如何在python和Google AppEngine中的集合上更改默认属性 - How to change the default property on a set in python and Google AppEngine 如何在Python Google Appengine数据存储区中实现一对一关系? - How to do one to one relation in python google appengine datastore? 如何在Python运行时中将任务排队到Google Appengine中的模块 - How does one queue a task to a module in google appengine in the Python runtime 如何使用 Google Drive API for python 与多个用户共享 Google Drive 中的文件? - How to share a file from Google Drive with more than one user using Google Drive API for python? 如何使用 python ebaysdk 从多变体列表中过滤项目(多个项目的列表) - How to use python ebaysdk to filter items from a multi variation listing (listing of more than one item) Python Pandas:如何过滤存储在不同变量中的多个表达式的数据帧? - Python Pandas: How to filter a dataframe with more than one expression stored in different variables? Python:如何在for中解压多个值? - Python: how to unpack more than one value in a for? 如何在python中调用多个函数 - How to call more than one function in python 如何在python中检查多个条件 - how to check more than one condition in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM