简体   繁体   English

如何在GAE中获得上级实体?

[英]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. 其中author是数据存储实体。

How do I access a "post"'s parent? 如何访问“帖子”的父母? I tried doing post.parent but apparently "parent" is a function. 我尝试做post.parent但显然“父母”是一个功能。 I was unable to find this in the docs. 我在文档中找不到这个。

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 https://developers.google.com/appengine/docs/python/datastore/keyclass#Key_parent

Try this: 尝试这个:

key_name = postIdForTitle(postInfo['title'])
parent = post.get_by_key_name(key_name).parent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM