See Django Book: Chapter 5 Models :
To sort by multiple fields (where the second field is used to disambiguate the order in cases where the first is the same), use several arguments:
That is, the correct call:
order_by('bedrooms', 'bathrooms')
In the context, according to the original question:
def sorts(): sort = ['bedrooms', 'bathrooms'] return sort posts = Post.objects.filter(**keyword_args).order_by(*sorts())
Happy coding.
user166390
source share