I want people to be able to sort things and not just me sorting things manually. So, for example, I will have a link to sorting, and the link will be something like, /?sort=issues and this would show a list of issues in alphabetical order, etc. Or /?sort=cover and it will show a list of issues with covers only.
Views.py
def issues(request):
issues_list = Issue.objects.order_by('-date_added')
paginator = Paginator(issues_list, 24)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
issues = paginator.page(page)
except (EmptyPage, InvalidPage):
issues = paginator.page(paginator.num_pages)
return render_to_response('comics/issues.html', {'issues': issues}, context_instance=RequestContext(request))
So, I’d want anyone to have the option of ordering by something like -date_added, date_addded, pub_date, importance, etc.
I’d imagine I’d have to fix my views and do some request.GET magic, but I am pretty new to Django and don’t really know how to go about doing this. I checked Django docs, too.
1 Answer