在 Google App Engine 中,如何在相互引用的两个实体之间使用引用属性?
如果我有两种类型的模型,每种模型都相互引用,则无论我尝试首先定义哪一种模型,都会表示它无法识别引用的其他类型(因为它是在文件中进一步定义的)。例如:
class Author(db.Model):
most_recent_book = db.ReferenceProperty(Book)
class Book(db.Model):
author = db.ReferenceProperty(Author)
这将声称引用的“Book”模型无法识别。如果我翻转订单,我会遇到同样的问题(除了它会说“作者”不被识别)。我该如何解决这个问题?
If I have two types of models that each reference each other, whichever one I try to define first says it does not recognize the referenced other type (because it is defined further down in the file). For example:
class Author(db.Model):
most_recent_book = db.ReferenceProperty(Book)
class Book(db.Model):
author = db.ReferenceProperty(Author)
This will claim that the referenced "Book" model is not recognized. If I flip the order, I run into the same issue (except it will say that "Author" is not recognized). How do I get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 ReferenceProperty,无需声明类型,如这篇文章中所述应用引擎提示
You can use ReferenceProperty without declaring a type as described in this article from AppEngine Tips