Saturday, May 14, 2011

Problems importing model classes that reference each other...

I am trying to create a simple billing/CRM app for my company. I have
create a Django project with the following apps:

sales_manager
office_manager
customer_manager

Within, I have models representing things like Customers, Contacts,
Projects, Tasks, etc. The problem I am having seems to arise from the
fact that I have model classes which reference each other. For
example, the customer_manager.models.py file starts like this:

from sales_manager.models import Contact

# Create your models here.

class Customer(models.Model):
"""
Customer class.

Model code: 'cu'
"""

cu_createdOn = models.DateTimeField('Created On',
auto_now_add=True)
cu_modifiedOn = models.DateTimeField('Last Modified
On',auto_now=True)
cu_lastAccessed = models.DateTimeField('Last Accessed
On',auto_now=True)
cu_active = models.BooleanField('Active', default=True)
...
cu_contacts = models.ManyToManyField(Contact,
verbose_name='Additional Contacts', null=True, blank=True)
cu_comments = models.TextField('Comments', null=True, blank=True)


And my sales_manager.models.py file starts like this:


from customer_manager.models import Customer

# Create your models here.


class Contact(models.Model):
"""
Contact class. Generic container for contacts of all kinds

Model code: 'ct'
"""

ct_createdOn = models.DateTimeField('Created On',
auto_now_add=True)
ct_modifiedOn = models.DateTimeField('Last Modified
On',auto_now=True)
ct_lastAccessed = models.DateTimeField('Last Accessed
On',auto_now=True)
ct_name = models.CharField('Name', max_length=64, null=True,
blank=True)
ct_email = models.EmailField('Email', null=True, blank=True)
...

The models class in the sales_manager.models imports Customer from
customer_manager.models and customer_manager.models imports Contact
from sales_manager.models. All of the model definitions appear okay,
but when I try to execute the syncdb command, I get import errors:


File "C:\Users\dave\Documents\django\my_it_office\..\my_it_office
\office_manager\models.py", line 2, in <module>
from customer_manager.models import Customer
File "C:\Users\dave\Documents\django\my_it_office\customer_manager
\models.py", line 2, in <module>
from sales_manager.models import Contact
File "C:\Users\dave\Documents\django\my_it_office\sales_manager
\models.py", line 2, in <module>
from office_manager.models import Staff
File "C:\Users\dave\Documents\django\my_it_office\office_manager
\models.py", line 2, in <module>
from customer_manager.models import Customer
ImportError: cannot import name Customer

How can I get around this? I would like to keep those models in
separate apps, but I also need for those apps to reference each others
models. Can someone help shed some light on this? I am looking at it
the wrong way?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate