From b914991b3705cb6c91013d962c55cda9deb18d83 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Wed, 6 Nov 2013 00:17:28 +0100 Subject: Added more tests and documentation for dictsort. It's possible to use something like {{ foo|dictsort:'bar.baz' }} but this wasn't tested or documented. --- docs/ref/templates/builtins.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'docs') diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index 48412239ad..d8f76dc680 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -1433,6 +1433,27 @@ then the output would be: {'name': 'zed', 'age': 19}, ] +You can also do more complicated things like:: + {{ for book in books|dictsort:"author.age" + * {{ book.title }} ({{ book.author.name }}) + {% endfor %} + +If ``books`` is: + +.. code-block:: python + + [ + {'title': '1984', 'author': {'name': 'George', 'age': 45}}, + {'title': 'Timequake', 'author': {'name': 'Kurt', 'age': 75}}, + {'title': 'Alice', 'author': {'name': 'Lewis', 'age': 33}}, + ] + +the the output would be:: + + * Alice (Lewis) + * 1984 (George) + * Timequake (Kurt) + .. templatefilter:: dictsortreversed dictsortreversed -- cgit v1.3