'Tripple Join with sum in django fails

How can I fetch such a query especially Mark is not attached to stream but the child's ClassInformation is the one that has the stream has_all_marks = Mark.objects.filter(marks_class=marks_class, year=year, term=term, exam_set=exam_set, child__classinformation__stream__id=stream).values('child').annotate( mtotal=Sum('marks')).order_by('-mtotal')

Right now the result I get is wrong. I get multiples for some mtotal



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source