Search code examples
pythongoogle-app-enginegoogle-cloud-datastorewebapp2

How do I get the parent entity in GAE?


I create a "Post" entity via the following line:

    post = Post(date=datetime.now(),title=postInfo['title'],body=postInfo['body'],postid=postIdForTitle(postInfo['title']),parent=author)

where author is a datastore entity.

How do I access a "post"'s parent? I tried doing post.parent but apparently "parent" is a function. I was unable to find this in the docs.


Solution

  • You can get a key of a parent entity from the key of your child entity. Look at the key Class:

    https://developers.google.com/appengine/docs/python/datastore/keyclass#Key_parent