0
使用Google App Engine for Python。看起來,當你在舊的db模型下連接數據存儲實體時,你可以很容易地獲得連接實體的列表,但我似乎無法用ndb做同樣的事情。使用ndb獲取連接實體的列表KeyProperty
我:
class User(ndb.Model):
username = ndb.StringProperty()
class Collection(ndb.Model):
owner = ndb.KeyProperty(User)
name = ndb.StringProperty()
photos = ndb.StringProperty(repeated=True)
因此,每個集合與所有者創建。我想我應該能夠得到用戶的收藏只是:
集合= user.collections
但是,其結果是:
collections = user.collections
AttributeError: 'User' object has no attribute 'collections'
從文檔,似乎可以做到這一點通過指定collection_name關鍵字,但我沒有看到ndb等效。
FWIW,我發現這個NDB小抄得心應手(在裏面搜索「逆向引用」,你會發現丹尼爾的回答):https://docs.google的.com /文件/ d/1AefylbadN456_Z7BZOpZEXDq8cR8LYu7QgI7bt5V0Iw/mobilebasic –