Friday, 23 August 2013

Ordering a (Django) list from a template

Ordering a (Django) list from a template

I have created a form which returns information to a list in a table,
using a mako template. I have it set up to order the list alphabetically
from A-Z when the list name is clicked, within the template and views.
The problem is, I want to be able to order it from Z-a if it is clicked
again. Here is my view:
def people(request):
sort = request.GET.get('sort','')
if sort != '':
var = sort
ppl = People.objects.order_by(var)
else:
ppl = People.objects.all()
And my template.mako:
<table class="table overview-table table-hover" id="people">
<thead>
<tr>
<th><a
href="${self.util.reverse('view_people')}?sort=first_name">First
Name</th>
<th><a
href="${self.util.reverse('view_people')}?sort=surname">Last
name</th>
</tr>
</thead>
Any ideas on how to get this to work

No comments:

Post a Comment