我正在嘗試創建一個具有單個祖先的根實體。當我嘗試從那個單一的祖先獲得父密鑰時,我會得到'無'。我在這裏錯過了什麼?使用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