当我将类从一个导入到另一个时,我遇到了问题。我有 那些不同模块的课程:
crm.py
from CRMContactInformation import CRMContactInformation
class CRM(rdb.Model):
"""Set up crm table in the database"""
rdb.metadata(metadata)
rdb.tablename("crms")
id = Column("id", Integer, ForeignKey("screens.id"),
primary_key=True)
screen_id = Column("screen_id", Integer, )
contactInformation = relationship(CRMContactInformation,
userlist=False, backref="crms")
....
CRMContactInformation.py
from CRM import CRM
class CRMContactInformation(rdb.Model):
"""Set up crm contact information table in the database"""
rdb.metadata(metadata)
rdb.tablename("crm_contact_informations")
id = Column("id", Integer, ForeignKey(CRM.id), primary_key=True)
owner = Column("owner", String(50))
.....
正如您所看到的,我有一个递归问题因为我导入了 CRMContactInformation中CRM和CRM中的CRMContactInformation。我有 这个错误或类似的错误:
“AttributeError:'module'对象没有属性”
我尝试更改导入整个路径的导入。它没用 出来。
我有什么方法可以使用元数据对象来访问 表的属性?或另一种解决方法?
提前致谢!
答案 0 :(得分:0)
延迟进口:
class CRM(rdb.Model):
"""Set up crm table in the database"""
rdb.metadata(metadata)
rdb.tablename("crms")
id = Column("id", Integer, ForeignKey("screens.id"), primary_key=True)
screen_id = Column("screen_id", Integer, )
....
from CRMContactInformation import CRMContactInformation
CRM.contactInformation = relationship(CRMContactInformation, userlist=False, backref="crms")