Reputation: 189
Say I have the models Teacher, Course, Student. Student model has a foreignKey one-to-many- to Course, and Course has a foreignKey one-to-many to Teacher. When getting a queryset of all Student objects, is there a way to query them based on Teacher?
Upvotes: 3
Views: 1214
Reputation: 4630
Say teacher
is a teacher's uuid/primary key then following look-up should work for you
Student.objects.filter(course__teacher=teacher)
Upvotes: 8