I want to incorporate a sorting feature which allows for multiple sorting variables.
I tried to pass .order_by() a function but it keeps failing when I try to include multiple fields. How do I do this?
if request.GET.get('size_sort')=='1':
def sorts():
sort='\'bedrooms\',\'bathrooms\''
return sort
posts=Post.objects.filter(**keyword_args).order_by(sorts())
This returns the traceback:
Invalid order_by arguments: ["'bedrooms','bathrooms'"]
See Django Book: Chapter 5 Models:
That is, the correct invocation is:
In context, consistent with the original question:
Happy coding.