I am using Google App Engine with python 2.7 and Django templates.
My object model is set up like this:
Class parent(db.Model):
parentName = db.StringProperty()
Class child(db.Mode):
childName = db.StringProperty()
parent = db.ReferenceProperty(parent, collection_name='children')
My python code passes all the parents to the template
qry_parents = parent.all()
parents = qry_parents.fetch(30)
template_values = {'parents':parents}
self.response.out.write(template.render(path, template_values))
Now, what I am trying to do, but can’t seem to figure out, is how to display a count of the children from the implied collection “children” in the parent object. Here is a sample of my template.html
<html>
<body>
<table>
{% for p in parents %}
<tr>
<td>{{ p.parentName }}</td>
<td>{{ p.children.items|length }}</td> <!-- always zero! -->
</tr>
{% endfor %}
</table>
</body>
</html>
I can’t seem to reference the right thing to get the count of children out of there. I feel like I’m close, because I’m getting zero, not None or null. Can someone point me in the right direction? Thanks much!
You don’t need
items.childrenis adb.Queryobject already. You’re best off doingp.children.countthough.