Re: Recursive(?) ManyToMany model

2006-03-27 Thread Glenn Tenney

On Mon, Mar 27, 2006 at 12:37:54PM -0800, wam wrote:
> Well, it was my understanding that since I have the potential of having
> many 'inspired by' documents linked to a particular document, and that
> any particular document could have inspired many other other documents,
> then that means I'm looking at a many to many relationship. 

Earlier you wrote:

class Doc(meta.Model):
 ...
 inspired_by = meta.ManyToManyField(Doc)

Based on your comments above, I think you mean:

This one Doc can have many other Docs which inspired it.  
That's a OneToMany relationship.

This Doc, and many others, can inspire other Docs -- that's not part of
either relationship above.

-- 
Glenn

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



Re: Recursive(?) ManyToMany model

2006-03-27 Thread wam

Malcolm Tredinnick wrote:
> Hi William,
> I may be missing something, but it sounds like you want a one-to-many
> (a.k.a. ForeignKey) relationship here. The 'one' side is the "self"
> document in each case with links to 'many' other documents. I don't
> believe a ManyToMany relationship is necessary here.
>

Well, it was my understanding that since I have the potential of having
many 'inspired by' documents linked to a particular document, and that
any particular document could have inspired many other other documents,
then that means I'm looking at a many to many relationship. This seems
to compare well to the example Many-to-Many relationship example given
at http://www.djangoproject.com/documentation/model_api/

Many   toMany
Pizzas can have multiple topppings, and any particular topping can be
on multiple pizzas.
Documents can have multiple inspirations, and any particular document
can have inspired many other subsequent documents.

Since posting my request, I also ran across the technique described at:
http://www.djangoproject.com/documentation/models/m2m_intermediary/
which seems to be applicable to my needs. I'll let you know how it
works out...

  -- William


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



Re: Recursive(?) ManyToMany model

2006-03-26 Thread Russell Keith-Magee
On 3/27/06, wam <[EMAIL PROTECTED]> wrote:
class Doc(meta.Model): title = meta.CharField(maxlength=50) contents = meta.TextField() inspired_by = meta.ManyToManyField(Doc) supercedes = meta.ManyToManyField(Doc)I've obviously been having problem with the recursive nature of the
definitions. I saw mention of using 'self' as a special arg forrecursive references in the initializer of a ForeignKey(), butManyToMany() doesn't seem to have this capability. Any suggestions?
As of the 0.91 release, you are correct - 'self' referencing doesn't exist for ManyToMany. This is one (of many) areas that is fixed in the magic-removal development stream. 
For future reference, when referring to another model, you can use either the model name as a python symbol, the model name as a string (useful for forward references), or the string 'self'. In your case, either 'Doc' or 'self' would work.
Magic-removal also has improved model validation code, which will pick up the other problem in your model - multiple references on the same table. You are currently describing two relations on the same table, but not providing a 'related_name' to differentiate between the two. 
Yours,Russ Magee 

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


Re: Recursive(?) ManyToMany model

2006-03-26 Thread Malcolm Tredinnick

Hi William,

On Sun, 2006-03-26 at 20:16 -0800, wam wrote:
> I have a model where I will have a pool of documents that will have
> several references to various other documents within the pool. For
> example, I'm trying to do something similar to the following:
> 
> class Doc(meta.Model):
>  title = meta.CharField(maxlength=50)
>  contents = meta.TextField()
>  inspired_by = meta.ManyToManyField(Doc)
>  supercedes = meta.ManyToManyField(Doc)
> 
> I've obviously been having problem with the recursive nature of the
> definitions. I saw mention of using 'self' as a special arg for
> recursive references in the initializer of a ForeignKey(), but
> ManyToMany() doesn't seem to have this capability. Any suggestions?

I may be missing something, but it sounds like you want a one-to-many
(a.k.a. ForeignKey) relationship here. The 'one' side is the "self"
document in each case with links to 'many' other documents. I don't
believe a ManyToMany relationship is necessary here.

Malcolm



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



Recursive(?) ManyToMany model

2006-03-26 Thread wam

I have a model where I will have a pool of documents that will have
several references to various other documents within the pool. For
example, I'm trying to do something similar to the following:

class Doc(meta.Model):
 title = meta.CharField(maxlength=50)
 contents = meta.TextField()
 inspired_by = meta.ManyToManyField(Doc)
 supercedes = meta.ManyToManyField(Doc)

I've obviously been having problem with the recursive nature of the
definitions. I saw mention of using 'self' as a special arg for
recursive references in the initializer of a ForeignKey(), but
ManyToMany() doesn't seem to have this capability. Any suggestions?

  -- William

P.S. This is my first 'real' Django app I've worked on outside of the
tutorial, so don't be surprised if you hear from me again. :-)


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