mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #25670 -- Allowed dictsort to sort a list of lists.
Thanks Tim Graham for the review.
This commit is contained in:
parent
cdbd8745f6
commit
e81d1c995c
6 changed files with 107 additions and 7 deletions
|
@ -1443,6 +1443,40 @@ then the output would be::
|
|||
* 1984 (George)
|
||||
* Timequake (Kurt)
|
||||
|
||||
``dictsort`` can also order a list of lists (or any other object implementing
|
||||
``__getitem__()``) by elements at specified index. For example::
|
||||
|
||||
{{ value|dictsort:0 }}
|
||||
|
||||
If ``value`` is:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
[
|
||||
('a', '42'),
|
||||
('c', 'string'),
|
||||
('b', 'foo'),
|
||||
]
|
||||
|
||||
then the output would be:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
[
|
||||
('a', '42'),
|
||||
('b', 'foo'),
|
||||
('c', 'string'),
|
||||
]
|
||||
|
||||
You must pass the index as an integer rather than a string. The following
|
||||
produce empty output::
|
||||
|
||||
{{ values|dictsort:"0" }}
|
||||
|
||||
.. versionchanged:: 1.10
|
||||
|
||||
The ability to order a list of lists was added.
|
||||
|
||||
.. templatefilter:: dictsortreversed
|
||||
|
||||
``dictsortreversed``
|
||||
|
|
|
@ -333,6 +333,9 @@ Templates
|
|||
|
||||
* Added the ``is`` comparison operator to the :ttag:`if` tag.
|
||||
|
||||
* Allowed :tfilter:`dictsort` to order a list of lists by an element at a
|
||||
specified index.
|
||||
|
||||
Tests
|
||||
~~~~~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue