"""
Ordering is set by a comma delimited ?ordering=... query parameter.
The ordering query parameter can be overridden by setting
the ordering_param value on the OrderingFilter or by
specifying an ORDERING_PARAM value in the API settings.
"""
params = request.query_params.get(self.ordering_param)
if params:
fields = [param.strip() for param in params.split(',')]
ordering = self.remove_invalid_fields(queryset, fields, view, request)
if ordering:
return ordering
# No ordering was included, or all the ordering fields were invalid
return self.get_default_ordering(view)
def filter_queryset(self, request, queryset, view):
ordering = self.get_ordering(request, queryset, view)
if ordering:
return queryset.order_by(*ordering)
return queryset
```
Посмотри код OrderingFilter из drf.filters
Окей
Обсуждают сегодня