Re: self referential manytomany

2008-02-22 Thread Michael Newman

I was afraid of that. Thanks Malcolm.

On Feb 22, 4:10 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> 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
-~--~~~~--~~--~--~---



Re: self referential manytomany

2008-02-22 Thread Malcolm Tredinnick


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
-~--~~~~--~~--~--~---



Re: self referential manytomany

2008-02-22 Thread Michael Newman

I am still having this problem. The simple solution is to put all of
the Models together, but I would prefer not to do this. I am pretty
sure that I have done this before. Is this something that has broken
recently in Django?



On Feb 21, 12:53 pm, Michael Newman <[EMAIL PROTECTED]> wrote:
> validation meaning python manage.py validate and python manage.py
> syncdb. I really don't know what is messing up other than the fact
> that module has a circular load. I have no idea to fix this one.
> Thanks Evert for your help. Anyone else?
>
> On Feb 21, 12:44 pm, Evert Rol <[EMAIL PROTECTED]> wrote:
>
> > > That would be true if I defined both models in the same models.py, and
> > > Profile was trying to use Bookmark before it was loaded in the file.
> > > Because this is an import the quotes won't work. That being said this
> > > in one model works when I don't need to put a import statement in it.
> > > So:
>
> > > profiles/models.py
> > > ###
>
> > > class Profile(models.Model):
> > > ...bookmarks = models.ManyToManyField(Webpage,
> > > related_name='bookmarks')
>
> > > from profiles.models import Profile
> > > ...author = models.ForeignKey(Profile)
>
> > > ###
> > > This validates, but it's not as modular as I would like. Any other
> > > ideas?
>
> > Sorry, my bad: I wasn't reading your previous mail properly.
>
> > Actually, I do this myself, but I don't apply validation.
> > In fact, what kind of validation do you mean? Just trying to run the
> > development server (providing everything is synced to the database),
> > ie, 'Python' validation; or something along the lines of form
> > validation? If the latter, perhaps importing Profile into the views.py?
> > It must be similar to using contrib.auth.user and extending the user
> > profile with your own class.
> > Otherwise, I'm currently out of suggestions...
>
> >Evert
>
> > >>> 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)
>
> > >> Michael, could this have to do with the note in this section:
> > >>http://www.djangoproject.com/documentation/model-api/#many-to-one-
> > >> relationships
> > >> "Note, however, that you can only use strings to refer to models in
> > >> the same models.py file -- you cannot use a string to reference a
> > >> model in a different application, or to reference a model that has
> > >> been imported from elsewhere."
> > >> So try to quote 'Profile', instead of importing it.
>
> > >>> I get an import error when I try to validate this. I realize that
> > >>> there is a little of cross referencing occurring, but I really
> > >>> cannot
> > >>> think of a better way to accomplish this. Any ideas?
>
> > >>> Thanks, Michael Newman
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: self referential manytomany

2008-02-21 Thread Michael Newman

validation meaning python manage.py validate and python manage.py
syncdb. I really don't know what is messing up other than the fact
that module has a circular load. I have no idea to fix this one.
Thanks Evert for your help. Anyone else?

On Feb 21, 12:44 pm, Evert Rol <[EMAIL PROTECTED]> wrote:
> > That would be true if I defined both models in the same models.py, and
> > Profile was trying to use Bookmark before it was loaded in the file.
> > Because this is an import the quotes won't work. That being said this
> > in one model works when I don't need to put a import statement in it.
> > So:
>
> > profiles/models.py
> > ###
>
> > class Profile(models.Model):
> > ...bookmarks = models.ManyToManyField(Webpage,
> > related_name='bookmarks')
>
> > from profiles.models import Profile
> > ...author = models.ForeignKey(Profile)
>
> > ###
> > This validates, but it's not as modular as I would like. Any other
> > ideas?
>
> Sorry, my bad: I wasn't reading your previous mail properly.
>
> Actually, I do this myself, but I don't apply validation.
> In fact, what kind of validation do you mean? Just trying to run the
> development server (providing everything is synced to the database),
> ie, 'Python' validation; or something along the lines of form
> validation? If the latter, perhaps importing Profile into the views.py?
> It must be similar to using contrib.auth.user and extending the user
> profile with your own class.
> Otherwise, I'm currently out of suggestions...
>
>Evert
>
>
>
> >>> 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)
>
> >> Michael, could this have to do with the note in this section:
> >>http://www.djangoproject.com/documentation/model-api/#many-to-one-
> >> relationships
> >> "Note, however, that you can only use strings to refer to models in
> >> the same models.py file -- you cannot use a string to reference a
> >> model in a different application, or to reference a model that has
> >> been imported from elsewhere."
> >> So try to quote 'Profile', instead of importing it.
>
> >>> I get an import error when I try to validate this. I realize that
> >>> there is a little of cross referencing occurring, but I really
> >>> cannot
> >>> think of a better way to accomplish this. Any ideas?
>
> >>> Thanks, Michael Newman
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: self referential manytomany

2008-02-21 Thread Evert Rol

> That would be true if I defined both models in the same models.py, and
> Profile was trying to use Bookmark before it was loaded in the file.
> Because this is an import the quotes won't work. That being said this
> in one model works when I don't need to put a import statement in it.
> So:
>
> profiles/models.py
> ###
>
> class Profile(models.Model):
> ...bookmarks = models.ManyToManyField(Webpage,
> related_name='bookmarks')
>
> from profiles.models import Profile
> ...author = models.ForeignKey(Profile)
>
>
> ###
> This validates, but it's not as modular as I would like. Any other
> ideas?

Sorry, my bad: I wasn't reading your previous mail properly.

Actually, I do this myself, but I don't apply validation.
In fact, what kind of validation do you mean? Just trying to run the  
development server (providing everything is synced to the database),  
ie, 'Python' validation; or something along the lines of form  
validation? If the latter, perhaps importing Profile into the views.py?
It must be similar to using contrib.auth.user and extending the user  
profile with your own class.
Otherwise, I'm currently out of suggestions...

   Evert

>>
>>> 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)
>>
>> Michael, could this have to do with the note in this section:  
>> http://www.djangoproject.com/documentation/model-api/#many-to-one- 
>> relationships
>> "Note, however, that you can only use strings to refer to models in
>> the same models.py file -- you cannot use a string to reference a
>> model in a different application, or to reference a model that has
>> been imported from elsewhere."
>> So try to quote 'Profile', instead of importing it.
>>
>>
>>
>>> I get an import error when I try to validate this. I realize that
>>> there is a little of cross referencing occurring, but I really  
>>> cannot
>>> think of a better way to accomplish this. Any ideas?
>>
>>> Thanks, Michael Newman
> >


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: self referential manytomany

2008-02-21 Thread Michael Newman

That would be true if I defined both models in the same models.py, and
Profile was trying to use Bookmark before it was loaded in the file.
Because this is an import the quotes won't work. That being said this
in one model works when I don't need to put a import statement in it.
So:

profiles/models.py
###

class Profile(models.Model):
...bookmarks = models.ManyToManyField(Webpage,
related_name='bookmarks')

from profiles.models import Profile
...author = models.ForeignKey(Profile)


###
This validates, but it's not as modular as I would like. Any other
ideas?

Thanks for tip anyway.

On Feb 21, 11:58 am, Evert Rol <[EMAIL PROTECTED]> wrote:
> On 21 Feb 2008, at 16:44 , 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)
>
> Michael, could this have to do with the note in this section: 
> http://www.djangoproject.com/documentation/model-api/#many-to-one-relationships
> "Note, however, that you can only use strings to refer to models in
> the same models.py file -- you cannot use a string to reference a
> model in a different application, or to reference a model that has
> been imported from elsewhere."
> So try to quote 'Profile', instead of importing it.
>
>
>
> > I get an import error when I try to validate this. I realize that
> > there is a little of cross referencing occurring, but I really cannot
> > think of a better way to accomplish this. Any ideas?
>
> > Thanks, Michael Newman
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: self referential manytomany

2008-02-21 Thread Evert Rol


On 21 Feb 2008, at 16:44 , 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)

Michael, could this have to do with the note in this section: http:// 
www.djangoproject.com/documentation/model-api/#many-to-one-relationships
"Note, however, that you can only use strings to refer to models in  
the same models.py file — you cannot use a string to reference a  
model in a different application, or to reference a model that has  
been imported from elsewhere."
So try to quote 'Profile', instead of importing it.


>
>
>
> I get an import error when I try to validate this. I realize that
> there is a little of cross referencing occurring, but I really cannot
> think of a better way to accomplish this. Any ideas?
>
> Thanks, Michael Newman
> >


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---