views:

74

answers:

1
+2  Q: 

Recursive problem

Hey guys,

I have a problem when I import classes from one to another. I have those classes in different modules:

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))
        .....

As you can see, I have a recursive problem because I import CRMContactInformation in CRM and CRM in CRMContactInformation. I got this error or similar:

“AttributeError: ‘module’ object has no attribute ”

I tried to change the imports importing the whole path. It didn't work out either.

Is there any way I can use the metadata object to access the attributes of the tables? or another way to solve this?

Thanks in advance!

A: 

Delay the imports:

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")
adw
It works, thanks!
bribon