mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
support filter_fields - adds compatibility with other filters
This commit is contained in:
parent
b8325ee576
commit
4edb973418
|
@ -28,9 +28,16 @@ class SimpleDjangoFilterBackend(BaseFilterBackend):
|
||||||
Really simple class that allows straightforward Django ORM filtering.
|
Really simple class that allows straightforward Django ORM filtering.
|
||||||
"""
|
"""
|
||||||
def filter_queryset(self, request, queryset, view):
|
def filter_queryset(self, request, queryset, view):
|
||||||
|
filter_fields = getattr('filter_fields', view, None)
|
||||||
|
if filter_fields is None:
|
||||||
|
filter_fields = request.QUERY_PARAMS.keys()
|
||||||
|
# reduce relations to entry point only
|
||||||
|
fields = [field.split('__')[0] for field in filter_fields.keys()]
|
||||||
params = {}
|
params = {}
|
||||||
for k, v in request.QUERY_PARAMS.iteritems():
|
for k, v in request.QUERY_PARAMS.iteritems():
|
||||||
params.update({k:v[0]})
|
# if entry point matches, collect the original key
|
||||||
|
if k.split('__')[0] in fields:
|
||||||
|
params.update({k: v[0]})
|
||||||
return queryset.filter(**params)
|
return queryset.filter(**params)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user