Sorting related items in a Django template
Is it possible to sort a set of related items in a DJango template? That is: this code (with HTML tags omitted for clarity): {% for event in eventsCollection %} {{ event.location }} {% for attendee in event.attendee_set.all %} {{ attendee.first_name }} {{ attendee.last_name }} {% endfor %} {% endfor %} displays almost exactly want I want. The only thing I want to change is I the list of attendees to be sorted by last name. I've tried saying something like this: {% for event in events %} {{ event.location }} {% for attendee in event.attendee_set.order_by__last_name %} {{ attendee.first_name }}