best_filters.listsort

best_filters.listsort(lst, col=None)

Sort a list or a list of lists/tuples

If no argument is given, the list is sorted like python does by default. If an argunment is given (int), the filter is expecting a list of lists/tuples and will sort following the column ‘col’ order

Examples :

>>> c = { 'lst': ['a','c','b'] }
>>> t = '''{% load best_filters %}
... sorted : {% for i in lst|listsort %}{{i}}{% endfor %}'''
>>> Template(t).render(Context(c))
'\nsorted : abc'
>>> c = { 'lst': [('a',3),('c',1),('b',2)] }
>>> t = '''{% load best_filters %}
... sorted : {% for i in lst|listsort:1 %}{{i|safe}}{% endfor %}'''
>>> Template(t).render(Context(c))
"\nsorted : ('c', 1)('b', 2)('a', 3)"