If i understand you correctly you've got a couple of solutions. You can define a "through" relationship between Student and Teacher usinf Techer_profile as the "through" table (http://docs.djangoproject.com/ en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships). Then you should be able to do:
teachers = Teacher.objects.filter(student__name="Jonny") I think the ORM should take care of this query for you and select only those teachers. Euan On Jun 22, 3:39 am, Jx <[email protected]> wrote: > Hi, > > i recently encountered a problem due to inefficient performance of > django pagination. After researching, i realized that there is a need > to use django database queries when dealing with django-pagination as > "LIMIT" will automatically be added. This is useful especially when > dealing with huge chunk of data. > > However, i came across a problem where i could not figure out how to > use django database query to extract the data. > > Lets say i have 3 tables, "Teachers", "Students", and > "Teachers_profile" with a one-many relationship. > > The Teacher table contains teacher_id,.....(teacher info) > The Student table contains student_id,name,...(student info) > The Teacher_profile table is the link between the 2 tables. It > contains teacher_id,student_id > > How can i use django database query with filters to extract the > teachers who is managing a student named "Jonny" for example? > > i'm not sure if this is an easy question, but i'm having some trouble > in solving it :( -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

