Reputation: 7809
I want to get some data from the Google Appengine ndb. I have the following code
keys = []
for field in self.request.arguments():
keys.append(ndb.Key(models.MyModel, int(id)))
# Some unrelevant code
for k in keys:
logging.info(k)
m = ndb.get_multi(keys)
for p in m:
logging.info(p)
This gives me this output:
INFO 2012-09-07 13:18:23,436 main.py:58] Key('MyModel', 42)
INFO 2012-09-07 13:18:23,436 main.py:58] Key('MyModel', 44)
INFO 2012-09-07 13:18:23,437 main.py:58] Key('MyModel', 42)
INFO 2012-09-07 13:18:23,437 main.py:58] Key('MyModel', 43)
INFO 2012-09-07 13:18:23,437 main.py:58] Key('MyModel', 44)
INFO 2012-09-07 13:18:23,443 main.py:62] None
INFO 2012-09-07 13:18:23,443 main.py:62] None
INFO 2012-09-07 13:18:23,443 main.py:62] None
INFO 2012-09-07 13:18:23,443 main.py:62] None
INFO 2012-09-07 13:18:23,444 main.py:62] None
I'm sure the models exist in the datastore with that id number. So what am I doing wrong?
Upvotes: 2
Views: 1571
Reputation: 2265
The id could be a string in your datastore. So Key('MyModel', '42') may be what you're looking for. Id's can be strings or integers. Here are the docs for further reading.
Edit: Do your MyModel entities have parent keys? If yes, then you'd need to include the parent when constructing the key.
Upvotes: 3