Unable to filter Node argument - datastore - google engine - python

Class user(ndb.Model): def post(self): name = db.StringProperty() age = db.StringProperty() Class search(webapp2.RequestHandler): def post(self): x = userData.query().filter("age >=",1) #error points to this line 

I get an error message: I can not filter the Node argument; got "age" = "

I follow the syntax specified at https://developers.google.com/appengine/docs/python/datastore/queries

Please let me know how to solve this problem.

+7
python google-app-engine google-cloud-datastore
source share
1 answer

I finally found the answer for this in
Google App Engine (python): filter users based on custom fields .
The docs for this are referenced at https://developers.google.com/appengine/docs/python/ndb/queries#properties_by_string

The property defined in the model class must be specified as ndb.GenericProperty (). For the code mentioned in the question, the filter syntax should be:

 x = userData.query().filter(ndb.GenericProperty("age") >= 1).get() 
+12
source share

All Articles