On Sun, Apr 5, 2009 at 11:43 AM, codecowboy <guy.ja...@gmail.com> wrote: > > Hi Everyone, > > I'm new to the Django community and I am having trouble with circular > imports. I've read every article that I can find about the issue > including posts on this group. I'm going to paste my model files and > the stack trace. I'm sure that this must be an issue that has come up > before. Thank you in advance for any help. If you know of an article > that explains the problem then point me to it. Thanks again. > > [snip]
Do you need to have two, parallel, many to many relationships between Scientist and Conference?. If the answer is no then yo don't need to define that relationship in both models. This alone almost solves your circular reference problem. The technique of using a string with the name of the model instead of tthe Model class onject iself to indicate the target of a relationship is only needed (and accepted) when: * The target model hasn't yet been defined (It comes after in the same application models.py file). * or when you have two mutually referencing relationships between two models located in diferent applications (actually, this second use case isn't clearly explained in our documentation) Using these guidelines and simplifying you example to the relevant bits, something like this could be a start of a solution to your problem: ------ scinet.scientists.models ----------- from django.db import models class Scientist(models.Model): # ... # no many to many field needed here ------ scinet.conferences.models ----------- from django.db import models from scinet.scientists.models import Scientist class ConferenceAttendee(models.Model): # ... conference = models.ForeignKey('Conference') scientist = models.ForeignKey(Scientist) class Conference(models.Model): # ... scientists = models.ManyToManyField(Scientist, through=ConferenceAttendee) Relevant documentation links worth reading: http://docs.djangoproject.com/en/dev/topics/db/models/#many-to-many-relationships http://docs.djangoproject.com/en/dev/topics/db/models/#models-across-files http://docs.djangoproject.com/en/dev/ref/models/fields/#lazy-relationships HTH -- Ramiro Morales http://rmorales.net --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---