Question

I usually tend to avoid giving such explicit examples, but in this case it's necessary.

I have 5 entities:

  1. Student
  2. Group
  3. StudentGroup
  4. CourseGroup
  5. Course (not relevant -- for completeness purpose only)

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

Était-ce utile?

La solution

ASSUMING CourseGroup has a foreignkey to StudentGroup and a foreignKey to a Course

Student.objects.filter(studentgroup=1, studentgroup__coursegroup__course=your_course)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top