views:

64

answers:

1

I'm using the regroup template tag to group queryset output on a Choices field. 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 the 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>

So type.grouper renders as 'tut' or 'org' on the page, rather than the long form. Normally you would use the get_foo_display syntax to get at the value of the choice, rather than the key. But the value doesn't seem to be available after going through regroup. There's no way I can find to use get_foo_display on {{type.grouper}}.

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

+2  A: 

What happens if you do

{% regroup resources by get_restype_display as resource_list %}
Daniel Roseman
It works! That's fantastic Daniel. I'll file a documentation patch for this.
shacker
Ticket and doc patch: http://code.djangoproject.com/ticket/13452
shacker