0

after going through some basic tutorials on the app engine and the webapp framework, I'm attempting to display documents that are related to a project construct I've created (e.g {% ifequal project.key doc.parentproject %} ) I have created several documents that do indeed have a doc.parentproject identical to keys from the project, but somehow this for loop never runs. If I substitute project.key for an actual project key value, then it returns true for those specific kets. Is there some basic templating thing I'm missing here? I haven't been able to find any answers on google or the django site (webapp uses the django templating engine). Any help would be appreciated.

Sorry if this is basic newb material...

{% for project in projects %} <blockquote> <div style="border:1px solid #999; padding:20px;"> <h3>{{ project.projectname|escape }} </h3> <h5>{{ project.key }}</h5> <table border="1" cellpadding="5" cellspacing="0" width="600"> <tr> <td>Doc Feed Name</td> <td>Feed author</td> <td>Spreadsheet URL</td> <td>Parent Project Key</td> <td>Created on</td> <td>&nbsp;</td> </tr> {% for doc in docs %} {% ifequal project.key doc.parentproject %} <tr> <td>doc name:{{ doc.name|escape }}</td> <td>{{ doc.author }}</td> <td>{{ doc.link }}</td> <td>{{ doc.parentproject }}</td> <td>{{ doc.date }}</td> <td>Delete</td> </tr> {% endifequal %} {% endfor %} </table> 

{% endfor %}

2 Answers 2

1

Without seeing the controller code that provides the values to this template, it is difficult to really diagnose the problem that you are having, but I would guess that the docs variable isn't getting the list of doc entities that it clearly expects.

From a good design standpoint, I would suggest giving the Project entity a property that contains a list of the docs that are associated with it. It looks like each doc is dependent on a parent project, so it would be cleaner and easier to have this code:

 {% for doc in project.docs %} ...do my rendering here... {% endfor %} 

than what you have.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, that's a great suggestion. I'm a newb here, so thinking about this differently helps a lot.
@travist: welcome to SO. It is customary to vote-up helpful / useful answers. You are also encouraged to accept the most helpful answer by clicking on the checkmark.
travist, you are quite welcome. Don't worry about feeling like a newb. Your question was actually well-written and included a useful code sample. That alone puts you in the top 5% of SO newbs.
0

If a "doc" is an entity, and "parentproject" is a ReferenceProperty on that entity, the problem here is that you're attempting to compare a Key with an entity (ReferenceProperties automatically resolve their references). You need to use this instead:

{% ifequal project.key doc.parentproject.key %} 

Comments