please help me on my problem I hope my title is enough to understand what I mean, please help me on this problem guys.
When I tried this:
id_list = g
This is the best I can do for you. I think you should be selected based on the student and filtering the grades to the teacher. I also did a prefetch for all of the subjects since I can't quite tell what you need done there.
students = Student.objects.filter(
grades__teacher_id=teacher.id,
).annotate(
total_avg=Avg('grades__Average')
).prefetch_related('grades__Subjects')
Template:
{% for student in students %}
{{teacher}}
{{student.grades.subjects.all}}
{{student}}
{{student.total_avg}}
{% endfor %}