Is there a better way to do the following:
if column_sort == 'size':
if sort == 'desc':
results = results.order_by('-size')
else:
results = results.order_by('size')
elif column_sort == 'modified':
if sort == 'desc':
results = results.order_by('-last_modified')
else:
results = results.order_by('last_modified')
else:
if sort == 'desc':
results = results.order_by('-path')
else:
results = results.order_by('path')
results = results[:100]
For example, a way in which to reverse the query order?
How about you just write the code once?
Oh yeah, I see that there’s some difference between sort fields and values, in which case you need a simple map, like
results.order_by(col_map[column_sort])