Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: encode/django-rest-framework
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 786cee75f6c11f5ab6283655ec4f89e2c15b6c18
Choose a base ref
..
head repository: encode/django-rest-framework
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ce35de5707078d80cd6a9be74420752b2e23ebfe
Choose a head ref
Showing with 4 additions and 3 deletions.
  1. +4 −3 rest_framework/filters.py
7 changes: 4 additions & 3 deletions rest_framework/filters.py
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
returned by list views.
"""
import operator
from typing import Iterable
import warnings
from functools import reduce
from typing import Iterable

from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured
from django.db import models
@@ -217,13 +217,14 @@ def get_schema_operation_parameters(self, view):
},
]


class OrderingExpressionFactory:

def __init__(self, queryset_value: str = '', nulls_as_low: bool = True):
self.queryset_value = queryset_value
self.nulls_as_low = nulls_as_low

def get_expression(self, given_value:str):
def get_expression(self, given_value: str):
queryset_value = self.queryset_value or given_value
if given_value.startswith('-'):
return models.F(queryset_value.strip('-')).desc(nulls_last=self.nulls_as_low)
@@ -248,7 +249,7 @@ class OrderingFilter(BaseFilterBackend):
ordering_description = _('Which field to use when ordering the results.')
template = 'rest_framework/filters/ordering.html'

def get_ordering(self, request, queryset, view): # returns an iterable of expressions for ordering
def get_ordering(self, request, queryset, view): # returns an iterable of expressions for ordering
"""
Ordering is set by a comma delimited ?ordering=... query parameter.