Django "with" template tag renders empty for ForeignKey relationship -


i using count method on queryset context variable more once in template, decided store in reusable variable:

{% album.photograph_set.count numphotos %}     <title>my title {{ numphotos }} in it</title>     <span>i use {{ numphotos }} here, too</span> {% endwith %} 

the numphotos variable seems blank, though replacing album.photograph_set.count inline still returns appropriate value. tried using {% numphotos=album.photograph_set.count %} syntax exhibits same behavior. use {% ... ... %} syntax elsewhere in code , works expected.

any appreciated.

if photograph_set reverse relationship of foreignkeyfield or if it's manytomanyfield, you'll need

{% album.photograph_set.all.count numphotos %} 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -