Python 需要帮助为一对多关系设置ndb.StructuredProperty吗

Python 需要帮助为一对多关系设置ndb.StructuredProperty吗,python,google-app-engine,Python,Google App Engine,我正在使用Python(2.7)和GAE创建一个应用程序。我试图建立一对多的关系。有一个客户拥有众多财产,也有许多潜在联系人。联系人还具有各种属性。使用的示例似乎非常简单,但当我导入带有结构化属性行的数据模型时,我的日志中不断出现以下错误: NameError:未定义名称“联系人” 任何帮助都将不胜感激 main.py from dataObjects import * class Client(ndb.Model): createDate = ndb.DateProperty()

我正在使用Python(2.7)和GAE创建一个应用程序。我试图建立一对多的关系。有一个客户拥有众多财产,也有许多潜在联系人。联系人还具有各种属性。使用的示例似乎非常简单,但当我导入带有结构化属性行的数据模型时,我的日志中不断出现以下错误:

NameError:未定义名称“联系人”

任何帮助都将不胜感激

main.py

from dataObjects import *
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()
dataObjects.py

from dataObjects import *
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()
正如所指出的那样:


“因为它尚未定义。请交换模型的顺序。”


基本上,在创建模型客户机时,您的代码需要一个联系人对象。由于您的代码不存在联系人,因此它会中断。

此外,对于无法仅更改定义顺序的情况,您可以在定义模型后添加属性(包括自引用):


您必须交换这两个模型的顺序,因为当您定义客户模型时,联系人模型尚未定义。

因为它尚未定义。交换模型的顺序,这么简单?真是个笨蛋!工作得很有魅力。感谢您的快速回复。