From Django documentation https://docs.djangoproject.com/en/1.11/ref/models/querysets/#order-by
You can also order by query expressions by calling asc() or desc() on the expression:
Entry.objects.order_by(Coalesce('summary', 'headline').desc())
Or another example from documentation https://docs.djangoproject.com/en/1.11/ref/models/expressions/#some-examples
# Expressions can also be used in order_by()
Company.objects.order_by(Length('name').asc())
Company.objects.order_by(Length('name').desc())
But when I try to use code like this:
sort = ['-some_field_name', Length('some_field_name').asc()]
current_obj = SomeModel.objects.get(pk=current_pk)
some_qs = SomeModel.objects.all().order_by(*sort)
prev_obj = prev_in_order(current_obj, qs=some_qs)
I get an error:
'OrderBy' object does not support indexing
in this file https://github.com/gregplaysguitar/django-next-prev/blob/master/next_prev.py in line 49
if field[0] == '-':
Could you please add support of Query Expressions and fix it?
From Django documentation https://docs.djangoproject.com/en/1.11/ref/models/querysets/#order-by
Or another example from documentation https://docs.djangoproject.com/en/1.11/ref/models/expressions/#some-examples
But when I try to use code like this:
I get an error:
'OrderBy' object does not support indexing
in this file https://github.com/gregplaysguitar/django-next-prev/blob/master/next_prev.py in line 49
if field[0] == '-':Could you please add support of Query Expressions and fix it?