views:

59

answers:

1

I need to retrieve institution name by going through an intermediate table. My view gets all the values except this one or at least it is not displaying in the template. Can someone please help with either revising my view or template statement?

http://dpaste.com/122204/

Thank you,

May

A: 

To debug these kinds of problems do the following.

Run the view function's processing separate from any template or any other parts of Django.

Either interactively or with a VERY simple script run your query. For example, use a simple script like this to explore your model and make sure your model really works.

from app.models import Contact, Institution, Whatever
results= Researchproject.objects.filter(restitlestrip__icontains='something').distinct()
for project in results:
    print project.contact
    print contact.institutionname

Note several things about your simple script and your template.

  1. Case matters. Project != project.

  2. Navigation matters. In the script shown above, contact is undefined. project.contact, however, is defined. Perhaps that's what you meant.

Your model appears incomplete. The Contactintermed table doesn't seem to be used anywhere in your query or view. It may have FK's to other tables, but you don't seem to have a sensible navigation from Project through Contact to Contactinterma to Institution.

Get your model to be correct in a stand-alone script. Add the template processing later.


Also, please post all the code here on StackOverflow. Chasing your code down all over the internet is a huge pain. It's far easier to simply ignore your question than it is to chase down your code.

S.Lott