Reputation: 73
I am following NDB Queries doc of GAE in Python, but can not continue with following errors:
# python google_appengine/remote_api_shell.py -s 127.0.0.1:8020
App Engine remote_api shell
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2]
The db, ndb, users, urlfetch, and memcache modules are imported.
dev~env> class Customer(ndb.Model):
... name = ndb.StringProperty()
...
dev~env> class Purchase(ndb.Model):
... customer = ndb.KeyProperty(kind=Customer)
... price = ndb.IntegerProperty
...
dev~env> c = Customer()
dev~env> c.name = 'lvqier'
dev~env> k = c.put()
dev~env> k
Key('Customer', 5629499534213120)
dev~env> p = Purchase()
dev~env> p.customer = k
dev~env> p.price = 10
dev~env> kp = p.put()
dev~env> Purchase.query(customer=c.key).fetch()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File ".../google_appengine/google/appengine/ext/ndb/model.py", line 3209, in _query
qry = Query(kind=cls._get_kind(), **kwds)
File ".../google_appengine/google/appengine/ext/ndb/utils.py", line 136, in positional_wrapper
return wrapped(*args, **kwds)
TypeError: __init__() got an unexpected keyword argument 'customer'
dev~env>
What I want to do is get all Purchase objects of a specific Customer. Where is wrong?
Upvotes: 1
Views: 450
Reputation: 12986
The arguments to the query and filter methods need to be expressions. So the query would look like
Purchase.query(Purchase.customer==c.key).fetch()
Probably worth going back over the docs, it is all outlined there. https://developers.google.com/appengine/docs/python/ndb/queries#filter_by_prop
Upvotes: 3