On Thu, 2008-02-21 at 08:44 -0800, Michael Newman wrote:
> I am a bit confused as to why it is that this gives me an error. I
> hope someone could explain it to me.
> 
> Let's say I have users with Profiles that can be connected to the one
> Web page that they can author. The other Users can bookmark that page.
> So my models look like this:
> 
> profiles.models.py
> 
> from bookmarks.models import Bookmark
> 
> class Profile(models.Model):
> ...bookmarks = models.ManyToManyField(Webpage)
> 
> ################
> bookmarks.models.py
> 
> from profiles.models import Profile
> ...author = models.ForeignKey(Profile)

These two models look too tightly coupled to be able to exist in
separate applications. What your code is saying is that before it can
construct the Profile model, it needs the Webpage model, because it
needs to create a foreign key. However, before it can create that model,
it needs the Profile model because of the foreign key in
bookmarks.models.

If A depends directly on B *and* B depends directly on A, then they
aren't orthogonal models and trying to put them in separate applications
isn't really gaining you anything (it's not like one can ever exist
without the other).

Django supports forward reference within the same file (via "string"
names ,rather than object references), however we don't support such
references across files because (a) it's a lot harder to implement
correctly because you need to track when to resolve the forward
references and (b) it's not really needed at the moment for the above
reason (two tightly coupled models in separate applications isn't
particularly good design).

Now, I could see myself arguing in favour of string/forward references
for models within the same application (but in different models files)
one day, because it makes splitting things up a bit cleaner. But not in
separate applications. However, that's also not a change that's
particularly high priority at the moment, given all the other stuff
we've got going on.

For now, if you've got this type of very tight coupling, put them in the
same file.

Malcolm

-- 
The hardness of butter is directly proportional to the softness of the
bread. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to