GAE/Django Templates (0.96) filters to get LENGTH of GqlQuery and filter it

Posted by Halst on Stack Overflow See other posts from Stack Overflow or by Halst
Published on 2010-03-28T14:53:43Z Indexed on 2010/03/28 15:53 UTC
Read the original article Hit count: 640

I pass the query with comments to my template:

    COMM = CommentModel.gql("ORDER BY created")

    doRender(self,CP.template,{'CP':CP,'COMM':COMM, 'authorize':authorize()})

And I want to output the number of comments as a result, and I try to do things like that:

    <a href="...">{{ COMM|length }} comments</a>

Thats does not work (yeah, since COMM is GqlQuery, not a list). What can I do with that? Is there a way to convert GqlQuery to list or is there another solution? (first question)

Second question is, how to filter this list in template? Is there a construct like this:

    <a href="...">{{ COMM|where(reference=smth)|length }} comments</a>

so that I can get not only the number of all comments, but only comments with certain db.ReferenceProperty() property, for example.

Last question: is it weird to do such things using templates?

© Stack Overflow or respective owner

Related posts about google-app-engine

Related posts about python