Reverse Relations With Django-gm2m Using "through" Relation
I don't understand how to follow many-to-many relations in the reverse direction with django-gm2m. Here is an example of an models.py: from django.db import models from django.cont
Solution 1:
As described in the documentation django-gm2m can only create the related reverse relation after you have added an instance to the *_set
(as you did with the X
objects), as it can't know on which models the reverse relation is needed.
If you would like to access the reverse relations without having added something before you need to specify on which models they should get created:
class Y(models.Model):
things = GM2MField(through='Yrel', A, B)
This somehow resembles Django's behaviour where you would also have to create the reverse relation for GenericForeignKey
manually.
Post a Comment for "Reverse Relations With Django-gm2m Using "through" Relation"