Reputation: 6611
I usually tend to avoid giving such explicit examples, but in this case it's necessary.
I have 5 entities:
StudentGroup
represents students who are part of a group. A CourseGroup
is a course the whole group is taking part in.
I want to get all students that are part of a Group
and are taking part in a specific Course
. So far, I've only managed to get all students in a group:
students = Student.objects.filter(studentgroup=1)
Not sure why I can say studentgroup=1
but it's fortunate. However there's no studentgroupcourse=1
:) Any help?
Edit: My models are: http://pastebin.com/07z1iEcw
Upvotes: 0
Views: 260
Reputation: 55962
ASSUMING CourseGroup
has a foreignkey to StudentGroup
and a foreignKey to a Course
Student.objects.filter(studentgroup=1, studentgroup__coursegroup__course=your_course)
Upvotes: 2