【问题标题】:How to define the models with Multiple to Multiple relationship in Google App Engine?如何在 Google App Engine 中定义具有多对多关系的模型?
【发布时间】:2011-05-14 17:54:35
【问题描述】:

我正在编写一个具有多对多关系的数据模型的 Google App Engine 应用程序。我想我做错了。我的数据模型类定义是:

class Project(db.Model):
    name = db.StringProperty()
    description = db.TextProperty()
    admin = db.ReferenceProperty(Appuser)
    website = db.LinkProperty()
    members = db.ListProperty(db.key, default=None)
    start_date = db.DateTimeProperty(auto_add_now = True)

class Appuser(db.Model):
    user_id = db.UserProperty()
    fullname = db.StringProperty()
    website = db.LinkProperty()
    involved_projects = db.ListProperty(db.key, default=None)
    current_project = db.ReferenceProperty(Project)

现在,每当我尝试运行它时,我都会在文件中收到一条错误消息,指出 Appuser is not defined。这是因为Appuser 类是在Project 之后定义的。我无法更改顺序,因为类Appuser 也有一个类Project 的ReferenceProperty 我会得到一个未定义的Project 错误。现在如何正确实现它。

【问题讨论】:

标签: python google-app-engine web-applications


【解决方案1】:

循环引用问题的快速解决方法是在 Project 中定义 admin 时删除 referenceance_class(实际上不需要验证)。

class Project(db.Model):
    admin = db.ReferenceProperty()

这并不理想,但应该可以解决问题。

【讨论】:

    猜你喜欢
    • 2010-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-15
    • 2016-09-19
    • 2011-03-17
    • 1970-01-01
    相关资源
    最近更新 更多