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 –