API endpoint for positions on a check-in list

This commit is contained in:
Raphael Michel
2017-12-20 15:07:31 +01:00
parent 50c3f025e2
commit f3c1296105
7 changed files with 511 additions and 4 deletions

View File

@@ -0,0 +1,23 @@
from rest_framework.filters import OrderingFilter
class RichOrderingFilter(OrderingFilter):
def filter_queryset(self, request, queryset, view):
ordering = self.get_ordering(request, queryset, view)
if ordering:
if hasattr(view, 'ordering_custom'):
newo = []
for ordering_part in ordering:
ob = view.ordering_custom.get(ordering_part)
if ob:
ob = dict(ob)
newo.append(ob.pop('_order'))
queryset = queryset.annotate(**ob)
else:
newo.append(ordering_part)
ordering = newo
return queryset.order_by(*ordering)
return queryset