def table_view(request):
    sort = request.GET.get('sort')
records = Record.objects.all()
if sort is not None:
    records = records.order_by(sort)
if headers[sort] == 'des':
    records = records.reverse()
Sortable tables in Django