1

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 %}
4

1 回答 1

5

Grouper 只是一个字符串,因此您必须从路由实例中获取名称。不确定它会起作用,但尝试{{ route.list.0.pickup.name }}(我假设拾取是带有名称字段的拾取模型的外键)而不是{{ route.grouper }}

于 2012-06-05T14:25:31.730 回答