简体   繁体   中英

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

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())
results = filter(lambda x: x.car.maxprice < int(self.carprice), holder)

It boils down to having to programmably handling the second filter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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