I want to do some sorting and what I have mind is doing a GET request with a parameter named ordering like this and the value will be the model atttribute that I will use to sort like this:
?order=['-age', 'height']
the problem is when I try to receive the order parameter.. The value is a list.
I tried using the ast like this:
if 'order' in request.GET:
import ast
order = ast.literal_eval(request.GET.get('order'))
queryset = queryset.order_by(*order)
It worked. However, I would like to avoid using the ast library, is there any other way around?
UPDATE
I did my parameter like this:
?order=-age,height
And just used split in python like this:
if 'order' in request.GET:
order = request.GET.get('order').split(',')
queryset = queryset.order_by(*order)