[Answer]-Django queryset ordering

0πŸ‘

βœ…

I’m away from my development machine right now, but I think you could just pass the list of ids to a new Queryset, pk__in=list_of_object_ids, and then use the native order_by function.

For example:

objs = Object.objects.filter(pk__in=list_of_object_ids).order_by('value_to_order_by')

Anyway, that’s what I would try first, though I’m sure there are better optimizations.

For example, instead of a list of object ids, you could pass a dictionary with a key:value pair that has the value you want to order by.

For example:

[{'obj_id':1,'obj_value':'foo'},{'obj_id':2,'obj_value':'foo'}]

Then use some lambda function to sort it, like here.

πŸ‘€tchaymore

1πŸ‘

Assuming you are currently displaying the data as a table, you could give chance to some javascript client side table sorter such as tablesorter. There are lots of javascript table sorte.

πŸ‘€esauro

Leave a comment