I have this structure of model objects:
Grade A:
b = models.ManyToManyField("B")
Grade B:
c = models.ForeignKey("C") d = models.ForeignKey("D")
Grade C:
d = models.ForeignKey("D")
This is the request I'm trying to get:
I want to get all objects B of object A, and then in each object B compare between object D and object cd
I know that we just go to collection B with a for loop and do this comparison. But I plunged into the ManyToMany relation, then I noticed that I can do the following:
bObjects = A.objects.all().b q = bObjects.filter(c__d=None)
This works, it gives me all the objects c with the None d field. But when I try the following:
q = bObjects.filter(c__d=d)
This gives me d not defined, but d is an object of type c in object B.
What could be the problem? I will be glad if you suggest a further way to complete this task. Usually I try to write my query in one operation with many, many helper objects and not using loops.
django django-models
Wasim
source share