1
0
mirror of https://github.com/django/django.git synced 2025-07-05 02:09:13 +00:00

[1.2.X] Fixed #13452 - Document that regroup can be used with any template lookup. Thanks shacker for the suggestion and draft patch.

Backport of r15108 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15109 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Timo Graham 2010-12-29 20:21:28 +00:00
parent 863240e336
commit 6c51b80c04

View File

@ -761,6 +761,27 @@ filter, if your data is in a list of dictionaries::
{% regroup people|dictsort:"gender" by gender as gender_list %}
Grouping on other properties
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Any valid template lookup is a legal grouping attribute for the regroup
tag, including methods, attributes, dictionary keys and list items. For
example, if the "gender" field is a foreign key to a class with
an attribute "description," you could use::
{% regroup people by gender.description as gender_list %}
Or, if ``gender`` is a field with ``choices``, it will have a
:meth:`~django.db.models.Model.get_FOO_display` method available as an
attribute, allowing you to group on the display string rather than the
``choices`` key::
{% regroup people by get_gender_display as gender_list %}
``{{ gender.grouper }}`` will now display the value fields from the
``choices`` set rather than the keys.
.. templatetag:: spaceless
spaceless