0
是否可以将动态实体类型分配给Expando模型?例如,我想用这种模式对于许多类型的动态实体:带动态类型的GAE NDB Expando模型
class Dynamic(ndb.Expando):
"""
Handles all "Post types", such as Pages, Posts, Users, Products, etc...
"""
col = ndb.StringProperty()
parent = ndb.IntegerProperty()
name = ndb.StringProperty()
slug = ndb.StringProperty()
现在我用的是“山坳” StringProperty
持有类(如“页面”,“文章”,等等)和查询每次都是“col”。
阅读文档后,我偶然发现了这个@classmethod:
class MyModel(ndb.Model):
@classmethod
def _get_kind(cls):
return 'AnotherKind'
这是否意味着我可以做到这一点?
class Dynamic(ndb.Expando):
"""
Handles all "Post types", such as Pages, Posts, Users, Products, etc...
"""
col = ndb.StringProperty()
parent = ndb.IntegerProperty()
name = ndb.StringProperty()
slug = ndb.StringProperty()
@classmethod
def _get_kind(cls):
return 'AnotherKind'
但我该如何动态替换'AnotherKind'?我可以做点像return col
吗?
谢谢!
我认为(阅读行之间),你应该仔细看看PolyModel。 –