Tim, This was super helpful. Thanks for the guidance. For anyone that finds this via search, I'd also recommend reading here:
http://www.djangoproject.com/documentation/db-api/#chaining-filters Dave On Feb 29, 5:52 am, Tim Chase <[EMAIL PROTECTED]> wrote: > > A few classes (sorry for the syntax shorthand): > > > def Test_Info (models.Model): > > date = ...datetimefield... > > name = ..charfield... > > > def Student_Tests (models.Model): > > grade = ...charfield... > > student = ...foreignkey(Students) > > teacher = ...foreignkey(Teacher) > > test_info = ...foreignkey(Test_Info) > > > def Teacher (models.Model): > > name = ..charfield... > > > If I want to find the names of all of the tests that a given Teacher > > gave, can I do this without for loops? What would the retrieval code > > look like? > > I believe it would look something like > > teacher = Teacher.get(id=42) > tests = Test_Info.objects.filter( > student_tests_set__teacher = teacher).distinct() > > You then have the set of "tests", from which you can iterate over > them in code: > > for test in tests: > print test.name, test.date > > or in a template > > {% for test in tests %} > <p> > <b>{{ test.name }}</b> > {{ test.date }} > </p> > {% endfor %} > > -tim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---