| 828 | |
| 829 | Grouping on other properties |
| 830 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 831 | |
| 832 | Any valid template lookup is a legal grouping attribute for the regroup |
| 833 | tag, including methods, attributes, dictionary keys and list items. For |
| 834 | example, if the "gender" field is a foreign key to a class with |
| 835 | an attribute "description," you could use:: |
| 836 | |
| 837 | {% regroup people by gender.description as gender_list %} |
| 838 | |
| 839 | Or, if the "gender" field is a CHOICES field rather than a foreign key, |
| 840 | it will naturally have a :ref:`get_FOO_display() |
| 841 | <extra-instance-methods>` method available as an attribute, allowing |
| 842 | you to group on the display string rather than the CHOICES key:: |
| 843 | |
| 844 | {% regroup people by get_gender_display as gender_list %} |
| 845 | |
| 846 | ``{{ gender.grouper }}`` will now display the value fields from the |
| 847 | CHOICES set rather than the keys. |
| 848 | |