开发者

In Google App Engine, how do I use reference properties between two entities that reference each other?

开发者 https://www.devze.com 2022-12-20 06:04 出处:网络
If I have two types of models that ea开发者_如何学编程ch reference each other, whichever one I try to define first says it does not recognize the referenced other type (because it is defined further d

If I have two types of models that ea开发者_如何学编程ch 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?


You can use ReferenceProperty without declaring a type as described in this article from AppEngine Tips

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号