Hello Karen, Yes, I seem confused here. I've been trying everything. The key is that this query works correctly in the postgres database to retrieve the institutionname (institution), using the contact id retrieved from Project:
select DISTINCT Institution.institution from Contactintermed, Institution, Project where Contactintermed.contact_id=Project.contact_id and Contactintermed.institution_id=Institution.id In Python after I do a search by keyword in the view to get the "results", I cannot get the template to display the institution name (which I call institution). The query must first retrieve the Project records. From the project records I can then grab the contactid, which is then used in the Contactintermed table, which then goes to the Institution table to retrieve the institution name (institution). The "results" statement, doesn't seem to drill down through the Contactintermed table, even though I've tried adding the select_related to the statement. def search(request): query = request.GET.get('qr', '') if query: qset = ( Q(restitlestrip__icontains=query) ) results = Project.objects.filter(qset).distinct() # original else: results = [] return render_to_response("search/search.html", { "results": results, "query": query, }) On Feb 18, 11:58 am, Karen Tracey <kmtra...@gmail.com> wrote: > On Wed, Feb 18, 2009 at 2:46 PM, May <adles...@gmail.com> wrote: > > > Hello Karen, > > > Here are my views and models: > > >http://dpaste.com/122204/ > > >http://dpaste.com/122224/ > > > The manytomany table is actually a tertiary table. I was just trying > > to use django terms, so people would understand what type of table. > > > Thanks for your help! > > So Contact doesn't have a foreign key to Institution but rather there's > another many to many sort of table that pairs Contacts with Institutions. > Which means I don't know what you are hoping to get from: > > {{Contact.institutionname|safe}} > > There are potentially many institutions associated with any given Contact > instance -- how are you expecting to come up with just one institution name > for a Contact? > > Karen --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---