I use |length
filter in my templates to display the recordcount of my objects, however I'm currently forced to use .count
since it seems that using the filter against a related set doesn't work! The following
{{ myobject.retatedObject_set.all|length }}
prints literally:
{{ myobject.retatedObject_set.all|length }}
And this:
{{ myobject.retatedObject_set.all.count }}
returns the expected result...
BUT: count() generates an extra SQL query, which is why I always use |length filter which doesn't! (see my answer: https://stackoverflow.com/a/18578147/267719 to question django - show the length of a queryset in a view)
Can this be considered a bug in the Django template engine? How can I avoid the extra query?
EDIT:
After an hard debug I realized that the problem was the use of the django-debug-toolbar (which prints in its panels each filter used as normal strings) plus the use of AngularJS (which has the same syntax for its templates). I solved by reconfiguring AngularJS to use different symbols:
config(function($interpolateProvider) {
$interpolateProvider.startSymbol('{$');
$interpolateProvider.endSymbol('$}');
});