Triste, ma non esiste tale funzionalità nel tag "se" di django. C'è un rumors that smarter if tag will be added in 1.2., almeno è nella lista High priority
.
In alternativa è possibile utilizzare "smart_if" tag from djangosnippets.com
O è possibile aggiungere il proprio filtro (stessa come filtro length_is) - ma è solo l'aggiunta più codice inutile :(
from django import template
register = template.Library()
def length_gt(value, arg):
"""Returns a boolean of whether the value is greater than an argument."""
try:
return len(value) > int(arg)
except (ValueError, TypeError):
return ''
length_gt.is_safe = False
register.filter(length_gt)
Per maggiori informazioni consultare il django docs
Una cosa curiosa: in 1.6 se si utilizzano spazi come 'myarr | length', django lo stamperà, ma se si prova a confrontare, si ottiene un errore. Per confrontare, ho dovuto rimuovere gli spazi. – aldux