Question

How can I get the Key from a model I just inserted with put()? I'm talking about the value from the Key column from this image: http://i.stack.imgur.com/hT7hQ.png

Also, what is exactly Key? IIRC it's something that GAE generates automatically, but how/why/what for?

Was it helpful?

Solution

You haven't said if you are using ndb, or db, however in both cases the key is a property of the entity. Prior to the put it may be incomplete, in addition with ndb with key is the returned value of the put() call

key = myobj.put()

# if you are using ndb you can get the key with
myobj.key

# if db use 
myobj.key()

I suggest you also have a read of the docs on keys - https://developers.google.com/appengine/docs/python/ndb/entities

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top