Austin
Austin

Reputation: 4566

Django regroup grouper

I have successfully implemented the regroup call in my template to order missed donations by a pickup_id. The goal was to display all the routes where a a missed donation occured, and a list of all the names underneath the route name. Pickup routes can have the same name so I was grouping by pickup_id. When I do that and call {{ route.grouper }} it returns the ID of the pickup of course. How can I call the field 'route' which displays the route name from grouper?

I was trying things like this...

{{ route.grouper.route }} 
{{ route.route.grouper }}

view

missed_routes = Donor.objects.filter(missed='YES').order_by('pickup_id')    

template

{% regroup missed_routes by pickup_id as missed_pickups %}
{% for route in missed_pickups %}
    <p>{{ route.grouper }}</p>
    <ul>
        {% for donor in route.list %}
            <li>{{ donor.last_name }}</li>
        {% endfor %}
    </ul>
{% endfor %}

Upvotes: 1

Views: 3343

Answers (1)

zaan
zaan

Reputation: 897

Grouper is just a string, so you have to get name from route instance. Not sure it's gonna work, but try {{ route.list.0.pickup.name }} (I assume that pickup is foreign key to Pickup model with name field) instead of {{ route.grouper }}

Upvotes: 5

Related Questions