[Django]-Django, queryset to return manytomany of self

10👍

Look at the documentation for the symmetrical argument to ManyToManyField:

When Django processes this model, it identifies that it has a ManyToManyField on itself, and as a result, it doesn’t add a person_set attribute to the Person class. Instead, the ManyToManyField is assumed to be symmetrical — that is, if I am your friend, then you are my friend.

If you do not want symmetry in many-to-many relationships with self, set symmetrical to False. This will force Django to add the descriptor for the reverse relationship, allowing ManyToManyField relationships to be non-symmetrical.

So, in order to use the related_name, set symmetrical=False.

Leave a comment