Answer the question
In order to leave comments, you need to log in
How to get the number of students of all courses of the current teacher?
there is a course model, the course has a teacher (foreignkey) and students (manytomanyfield)
the task is to get the number of students from all courses of a particular teacher. How easy and simple is it to implement? Or do you have to loop through?
Describe with an example, please)
Answer the question
In order to leave comments, you need to log in
Try this code to count the number of teacher's students
teacher_student_count = User. courses.all().aggregate(Count('students')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question