我正在尝试创建一个具有单个祖先的根实体。当我尝试从那个单一的祖先获得父密钥时,我会得到'无'。我在这里错过了什么?使用Google Appengine在数据存储中创建父关系
这是我的示例代码:
# create a single root with key_name = 'home'
root = Page.get_or_insert('home')
# delay added for consistency
time.sleep(1)
# create an ancestor with the parent key set to the key of the root
start_page = Page(parent=root.key(), page_name="", content="<h1>welcome home</h1>")
start_page.put()
time.sleep(1)
child = Page.all().ancestor(root.key())
utils.log('==>> %s' % child.get().key())
上述输出线的根的密钥,而不是子。
这是为什么?
当我看着我的本地机器上的数据存储浏览器,这是我所看到的: 我没有看到这是指其父孩子的任何数据。
我最终的目标是从这个父母或其他父母创建许多子页面。我知道ReferenceProperty数据类型,但是这似乎是一个更自然的数据模型,因此可以使用更多的Pythonic。
是的,阅读get的文档我现在可以看到get()“执行查询并返回第一个**结果,如果没有找到结果,则返回None”。至于祖先()doc入口并没有说它也会返回祖先,所以我会就此提出一个doc问题。谢谢!! – timebandit 2014-10-20 12:30:26