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
- [Answer]-Module has no attribute 'index'?
- [Answer]-Django-tastypie how to assign default value in id
- [Answer]-Why absolute paths in Django settings
Source:stackexchange.com