Combining rearrangement with get_foo_display in Django templates

I use the regroup tag to group the query output into the Select box. In the model:

RESOURCE_TYPES = ( ('tut','External tutorial'), ('read','Additional reading'), ('org','Company or organization'), ) restype = models.CharField('Resource type',max_length=6,choices=RESOURCE_TYPES) 

in view:

 resources = Resource.objects.filter(tutorial=tutorial) 

in the template:

 {% regroup resources by restype as resource_list %} {% for type in resource_list %} <h3>{{type.grouper}}</h3> 

Thus, type.grouper displays as "tut" or "org" on the page, rather than a long form. Normally, you should use the get_foo_display syntax to get the value of the selection, not the key. But the value does not seem to be available after regrouping. I cannot find how to use get_foo_display in {{type.grouper}}.

It makes sense when you think about it, but what is the workaround? Thanks.

+7
django templates
source share
1 answer

What happens if you do

 {% regroup resources by get_restype_display as resource_list %} 
+13
source share

All Articles