简体   繁体   English

在Google App Engine上存储数据或查询数据的最佳方法

[英]The best way to store data or query data on google app engine

I want to be able to store some data in app engine and I am looking for some help on the best way to store the data or retrieve the data through a query. 我希望能够在App Engine中存储一些数据,并且我正在寻找有关存储数据或通过查询检索数据的最佳方法的帮助。 I have a list of users and want them to be able to add cars they want to sell and enter a lower and upper limit they would accept. 我有一个用户列表,希望他们能够添加他们要出售的汽车,并输入可接受的下限和上限。 When a user is searching for a car and enters a price, if this price is between the lower and upper limits, it will return the car: 当用户搜索汽车并输入价格时,如果此价格介于上限和下限之间,则会退回汽车:

class User(ndb.Model):
    username = ndb.StringProperty()
    cars = ndb.StructuredProperty(Car, repeated = True)
    datecreated = ndb.DateTimeProperty(auto_now_add = True)
    date_last_modified = ndb.DateTimeProperty(auto_now = True)

class Car(ndb.Model):
    lowerprice = ndb.IntegerProperty()
    maxprice = ndb.IntegerProperty()
    make = ndb.StringProperty()
    model = ndb.StringProperty()
    datecreated = ndb.DateTimeProperty(auto_now_add = True)
    date_last_modified = ndb.DateTimeProperty(auto_now = True)

I can't filter on: 我无法过滤:

c = User.query(User.car.lowerprice >= int(self.carprice), User.car.maxprice < int(self.carprice)).get())

As it returns BadRequestError: Only one inequality filter per query is supported. 返回BadRequestError时:每个查询仅支持一个不等式过滤器。

Should I structure or store the data differently to allow filtering on one inequality or should I try and use and and / or query? 我是否应该以不同的方式构造或存储数据以允许对一个不等式进行过滤,还是应该尝试使用和和/或查询?

Is there anything else you would recommend? 您还有其他建议吗?

Try something like this: 尝试这样的事情:

holder = User.query(User.car.lowerprice >= int(self.carprice)).get()) 持有人= User.query(User.car.lowerprice> = int(self.carprice))。get())
results = filter(lambda x: x.car.maxprice < int(self.carprice), holder) 结果=过滤器(lambda x:x.car.maxprice <int(self.carprice),持有人)

It boils down to having to programmably handling the second filter. 归结为必须以可编程方式处理第二个过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM