Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to pull out information about a specific instructor from the objects I get back and relate them to each other? Say I have the following tables:

Instructor:

id   name          summary
======================================
1     Joe          Bacon ipsum dolor sit
2     John         Shankle venison tri-tip
3     Jim          Spare ribs pastrami strip

Course:

id   name            description                   instructors
=====================================================================
1    algorithm       Bacon ipsum dolor sit         Joe, Tim
2    python          Shankle venison tri-tip       John
3    ruby on rails   Spare ribs pastrami strip     Matt, Joe, Sean

Review:

id    course_id          body
==================================================
1     1                  Bacon ipsum dolor sit
2     1                  Shankle venison tri-tip
3     2                  Spare ribs pastrami strip
4     2                  Bacon ipsum dolor sit
5     2                  Bacon ipsum dolor sit
6     3                  Spare ribs pastrami strip

and the following function to get the information about the instructor, how do I pull the reviews for a specific instructor (ex: Joe)?

def instructor(req, key):
    instructor = get_object_or_404(Instructor, key=key)
    courses = Course.objects.all_ordered(sort).filter(instructors=instructor)

    reviews = Review.objects.filter(......) ????????

    return(req, 'blah.html', vars())

For example, if the instructor is "Joe", the variable "reviews" should have 3 records:

id    course_id          body
==================================================
1     1                  Bacon ipsum dolor sit
2     1                  Shankle venison tri-tip
6     3                  Spare ribs pastrami strip
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.