views:

25

answers:

1

Hi Guys,

I am using the regroup feature of Django to group by "team", here is my code:

    {% regroup show_detail.cast_set.all by team as cast_list %}
    <ul>
    {% for cast in cast_list %}
      <li>{{ cast.grouper }}
        <ul>
          {% for item in cast.list %}
            <li>{{ item.name }} </li>
          {% endfor %}
        </ul>
      </li>
    {% endfor %}
    </ul>

This works fine. However, the cast.grouper is integer field with choices, typically I would do {{ cast.get_team_display }} to render the text, not the integer. Is there anyway to do this with the grouper? If this helps whats rendering now is this:

  • 2
    • Craig Mason
  • 1
    • Lindsay Price
    • Nicole Lee

What it actually should be is:

  • Creative Team
    • Craig Mason
  • Starring
    • Lindsay Price
    • Nicole Lee

Snippet of my model for you as well if this helps. STARRING = 1 CREATIVE = 2

TEAM_TYPE = (
    (CREATIVE, 'Starring'),
    (STARRING, 'Creative Team'),
)

name = models.CharField(max_length=200)
team = models.IntegerField(blank=True, null=True, choices=TEAM_TYPE)
A: 

Can you not just use get_team_display as the field to regroup on?

{% regroup show_detail.cast_set.all by get_team_display as cast_list %}
Daniel Roseman
I've tried that, no luck with that either, I put a PDB in to see what was available to double check and dir() showed get_team_display in there but it seems it's not accessible from the regroup, for whatever reason. That would be very odd.
JeffTaggary