gpt4 book ai didi

python - 如何在Google App Engine中定义具有多对多关系的模型?

转载 作者:行者123 更新时间:2023-12-01 06:10:49 25 4
gpt4 key购买 nike

我正在编写一个 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 。发生这种情况是因为类 Appuser 是在 Project 之后定义的。我无法更改顺序,因为类 Appuser 也有一个类 Project 的 ReferenceProperty 我会收到 Project 未定义的错误。现在如何正确实现这一点。

最佳答案

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

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

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

关于python - 如何在Google App Engine中定义具有多对多关系的模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6003756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com