我正在使用Python(2.7)和GAE创建一个应用程序。我正在尝试建立一对多的关系。有一个客户拥有多处房产,也有许多潜在联系人。联系人还具有各种属性。使用ndb.StructuredProperty的示例看起来很简单,但是当我导入带有结构化属性行的数据模型时,我的日志中不断出现以下错误:
名称错误:未定义名称“Contact”。你知道吗
任何帮助都将不胜感激。你知道吗
主.py
from dataObjects import *
数据对象.py
class Client(ndb.Model):
createDate = ndb.DateProperty()
name = ndb.StringProperty()
address1 = ndb.StringProperty()
address2 = ndb.StringProperty()
state = ndb.StringProperty()
zipCode = ndb.StringProperty()
phone = ndb.StringProperty()
fax = ndb.StringProperty()
website = ndb.StringProperty()
city = ndb.StringProperty()
industry = ndb.StringProperty()
status = ndb.StringProperty()
notes = ndb.StringProperty()
financing = ndb.StringProperty()
contacts = ndb.StructuredProperty(Contact, repeated=True)
class Contact(ndb.Model):
firstName = ndb.StringProperty()
lastName = ndb.StringProperty()
role = ndb.StringProperty()
status = ndb.StringProperty()
phone = ndb.StringProperty()
fax = ndb.StringProperty()
email = ndb.StringProperty()
createDate = ndb.DateProperty()
isClient = ndb.StringProperty()
address = ndb.StringProperty()
此外,对于无法仅更改定义顺序的情况,可以在定义模型后添加属性(包括自引用):
必须交换这两个模型的顺序,因为在定义客户机模型时,没有定义联系人模型。你知道吗
正如Daniel Roseman指出的:
“因为它还没有定义。交换模型的顺序。”
基本上,在创建模型客户机时,您的代码需要一个Contact对象。因为你的代码不存在联系人,所以它会中断。你知道吗
相关问题 更多 >
编程相关推荐