Re: How to make recursive ManyToMany relationships through an intermediate model symmetrical

2020-10-16 Thread David Nugent
After playing with this to answer your question and to correct my previous response, I found that it does work as documented when using a "through" model without using "through_fields". from django.db import models class Person(models.Model): name = models.CharField(max_length=255) fr

Re: How to make recursive ManyToMany relationships through an intermediate model symmetrical

2020-10-16 Thread gjgilles via Django users
Thanks for all for the replies! @David, the helper function works as expected. >>> from people.models import Person, Friendship >>> bill = Person(name='bill') >>> bill.save() >>> ted = Person(name='ted') >>> ted.save() >>> bill.add_friendship(ted, True) (, True) >>> bill.friends.all() ] ted.f

Re: How to make recursive ManyToMany relationships through an intermediate model symmetrical

2020-10-16 Thread David Nugent
Just to add, I don't think django supports symmetrical M2M relations with additional data / explicit through model without the shim I suggested. For example, this works: from django.db import models class Person(models.Model): name = models.CharField(max_length=255) friends = models.M

Re: How to make recursive ManyToMany relationships through an intermediate model symmetrical

2020-10-16 Thread coolguy
With your example, you can also find the records through>>> ted.person_set.all(). On Friday, October 16, 2020 at 7:05:51 PM UTC-4 David Nugent wrote: > This is expected with your code. You've created an asymmetric > relationship from bill to ted, but not the reverse. This would be > appropri

Re: How to make recursive ManyToMany relationships through an intermediate model symmetrical

2020-10-16 Thread David Nugent
This is expected with your code. You've created an asymmetric relationship from bill to ted, but not the reverse. This would be appropriate in a "follow" relationship. For symmetric relationships you need to create records in both directions. There are a few ways to do this but a helper functio

How to make recursive ManyToMany relationships through an intermediate model symmetrical

2020-10-16 Thread gjgilles via Django users
There are no responses to the same question on stackoverflow, so hopefully someone here can provide a solution.   I've read the docs.