Wednesday, July 31, 2013

many-to-many between apps

Is it possible to establish a many-to-many relationship between a model
in one app and a model in another app?

I've just tried to do it and run into what I think is circular import
trouble. This is a retro-fit after initial deployment.

#in item.models.reference
class Reference(models.Model):
... various fields ...
class Meta:
app_label = 'item'

#in item.models.reference_region
from company import Region

class Reference_Region(models.Model):
region = models.ForeignKey(Region)
reference = models.ForeignKey(Reference)
class Meta:
app_label = 'item'

#in company.models.region
from item import Reference

class Region(models.Model):
... various fields ...
ref = models.ManyToManyField(Reference)

I have tried it the other way declaring the many-to-many field in
Reference and the same thing happens.

ImportError: cannot import name Reference
ImportError: cannot import name Region

Any ideas appreciated



You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment