Python NDB多对多KeyProperty类引用不起作用
我正在尝试使用App Engine中的KeyProperties将各种实体相互链接,如下所示:Python NDB多对多KeyProperty类引用不起作用,python,google-app-engine,google-cloud-datastore,app-engine-ndb,Python,Google App Engine,Google Cloud Datastore,App Engine Ndb,我正在尝试使用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 = n
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中的类赋值就可以了,并且一切都可以运行。不过,我需要循环引用它们,这似乎应该行得通
我做错什么了吗?在这种情况下,您可以将种类作为字符串传递:
class ModelA(ndb.Model):
mod_bs = ndb.KeyProperty(kind='ModelB', repeated=true)
mod_cs = ndb.KeyProperty(kind='ModelC', repeated=true)
# other properties