Hi all,
I have this structure of model objects:
Class A : b = models.ManyToManyField("B")
Class B: c = models.ForeignKey("C) d = models.ForeignKey("D)
Class C: d = models.ForeignKey("D)
This is the query I'm trying to get: I want to get all the B objects of object A , then in each B object to make comparison between the D object and the c.d object. I know that simply move on the B collection with for loop and make this comparison. But I dived on the ManyToMany relation , then I noticed I can do the following :
bObjects = A.objects.all().b
q = bObjects.filter(c_d=None) this is working , it gives me all the c objects with None d field. but when I try the following : q = bObjects.filter(c_d=d) //Give me d not defined. but d is an object like c in the object B.
What can be the problem. I'll be happy if you suggest further way to do this task. I generally I'm trying to write my query in a single operation with many to many sub objects and not using loops.
Thanks in advance,