-1

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: https://i.stack.imgur.com/hT7hQ.png

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

alexandernst
  • 14,352
  • 22
  • 97
  • 197

1 Answers1

2

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

Tim Hoffman
  • 12,976
  • 1
  • 17
  • 29