【发布时间】:2014-04-25 21:11:14
【问题描述】:
我正在尝试使用 App Engine 中的 KeyProperties 将各种实体相互链接,如下所示:
class ModelA(ndb.Model):
mod_bs = ndb.KeyProperty(kind=ModelB, repeated=true)
mod_cs = ndb.KeyProperty(kind=ModelC, repeated=true)
# other properties
class ModelB(ndb.Model):
mod_as = ndb.StringProperty(kind=ModelA, repeated=true)
mod_cs = ndb.StringProperty(kind=ModelC, repeated=true)
# other properties
class ModelC(ndb.Model):
mod_cs = ndb.KeyProperty(kind=ModelA, repeated=true)
mod_as = ndb.KeyProperty(kind=ModelB, repeated=true)
# other properties
但我收到一条错误消息,指出此结构中未定义“ModelB”。显然,下面定义的任何被引用的地方都无法识别。因此,如果我摆脱了 ModelA 和 ModelB 中的类型分配,ModelC 中的那些就很好,一切都可以运行。不过,我需要循环引用它们,而且看起来应该可以。
我是不是做错了什么?
【问题讨论】:
标签: python google-app-engine google-cloud-datastore app-engine-ndb