doing queries in django templates

Well it seems that you can’t do ‘generic’ queires from within a template — the only reason being as I can tell– that functions don’t take parameters when you call them from within a tempalte. Pity.

Therefore the way to query within a template is to make a ‘helper function’ that will do your query for you, if possible.

I think. According to this post
* Attribute access of a related object which hadn’t previously been
accessed (and select_related will work around that for you so you get
all the queries up-front).
* Method accesses which fetch data (these should be documented in your models).
* Template tags which execute SQL (these should be documented in the
template tags which are executing the SQL).

So just build a helper function and hope it helps 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.