On Thu, Jan 8, 2009 at 12:06 PM, rabbi <[email protected]> wrote:

>
> Hi,
> I have a question that is probably very simple to answer.
>
> class Example(models.Model):
>    value = models.CharField(max_length=200)
>    related_examples = models.ManyToMany
> ('self',related_name='related_example_set')
>
> If I define a ManyToMany relationship like the one above and I want to
> access all Example's that are related to a specific Example instance,
> which of the following methods should I use?
>
>   1) related_examples.all()
>   2) related_examples.all().append(related_example_set.all())
>
> The reason I ask is that it is possible that one instance is assigned
> a relationship to another instance, but the relationship is not
> defined in the other direction.
>
> E.g. x.add(y) BUT NOT y.add(x)
>
>
ManyToMany fields to 'self' are symmetrical by default:

http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyFields.symmetrical

Since you have not specified symmetrical=False I do not think your 2nd
option will even work, since per the docs the example_set attribute will not
be created for a symmetrical ManyToMany relationship to 'self'.

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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