Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot filter a non-Node argument - datastore - google app 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: Cannot filter a non-Node argument; received 'age >='

I am following the syntax mentioned at https://developers.google.com/appengine/docs/python/datastore/queries

Please let me know how to resolve this issue.

like image 473
Krishna Chaitanya Avatar asked Nov 01 '13 03:11

Krishna Chaitanya


1 Answers

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

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

x = userData.query().filter(ndb.GenericProperty("age") >= 1).get()
like image 93
Krishna Chaitanya Avatar answered Oct 18 '22 01:10

Krishna Chaitanya