I have 4 models and I want to get a connection between them
Modela
class ModelA(models.Model): product = models.ForeignKey(ModelB) group = models.ForeignKey(Group)
ModelB
class ModelB(models.Model): title = models.CharField()
model
class ModelC(models.Model): product = models.ForeignKey(ModelB) group = models.ForeignKey(ModelD)
Modeld
class ModelD(models.Model): name = models.CharField()
Now I want all my ModelA objects to be combined with ModelB , ModelC and ModelD. In sql, it's pretty easy. Just create joins between tables. With Django ORM, I'm stuck because I can only do a direct relationship.
I'm doing it
ModelA.objects.all().select_related(product)
But I canโt join ModelC I already read this article , but I donโt want to go through my big list, do a simple thing! And I want to get into the database only once.
I am using the latest version of Django, and I hope that there is already a solution for this that I do not know about.
Thanks.
balsagoth
source share