Skip to content Skip to sidebar Skip to footer

How Can I Get The Custom Nested Data In Django?

I have four model as bellow: class AModel(models.Model): name = models.CharField(max_length=11) class BModel(models.Model): name = models.CharField(max_length=11) a =

Solution 1:

It is not the actual code but pseudo code which will give you the idea.

data_of_C_in_D = D.C_set # gives all value of C in D
Data_of_B_in_C = for i in data_of_C_in_D:
                     B.i_set #gives all value of C in B

....

Similarly you can go from D -- > A by making the set of each of them and then iterating over them. Check here for more

Django reverse lookup of foreign keys

It is called foreign key reverse lookup


Post a Comment for "How Can I Get The Custom Nested Data In Django?"