1👍
✅
You in fact have a many to many relationship between Peri
and Tooth
thru the PeriTask
model. The simplest thing to do would be to explicitely declare this relationship (in either Tooth
or Peri
) so the orm knows about it an add the appropriate descriptor to your models, cf https://docs.djangoproject.com/en/1.7/topics/db/models/#intermediary-manytomany :
class Tooth(models.Model):
#fields
customer = models.ForeignKey(Customer)
peris = models.ManyToManyField("Peri", through="PeriTask")
Then you have access to a given peri
‘s related theeth
with peri.tooth.all()
.
Source:stackexchange.com