[Answer]-Django-Haystack – How to sort using get parameters?

1👍

Override get_queryset method of haystack and add your sorting fields to your index model, for example:

class LinkListView(ListView):
    context_object_name = “link”

    def get_queryset(self):
        sort = self.request.GET.get(‘sort_by’)
        if sort:
            return Link.published.filter().order_by('{0}'.format(sort))
        else:
            return Link.published.filter().order_by('-date_inserted')

Leave a comment