Skip to content

Commit

Permalink
Version 3.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Aug 5, 2020
1 parent de497a9 commit eb2c4c2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.sql.constants import ORDER_PATTERN
from django.template import loader
from django.utils.encoding import force_str
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -256,7 +255,13 @@ def get_valid_fields(self, queryset, view, context={}):

def remove_invalid_fields(self, queryset, fields, view, request):
valid_fields = [item[0] for item in self.get_valid_fields(queryset, view, {'request': request})]
return [term for term in fields if term.lstrip('-') in valid_fields and ORDER_PATTERN.match(term)]

def term_valid(term):
if term.startswith("-"):
term = term[1:]
return term in valid_fields

return [term for term in fields if term_valid(term)]

def filter_queryset(self, request, queryset, view):
ordering = self.get_ordering(request, queryset, view)
Expand Down

0 comments on commit eb2c4c2

Please sign in to comment.