From de95598a1ed7f1b609b9dbc6415655be65fae4a8 Mon Sep 17 00:00:00 2001 From: tony Date: Fri, 15 May 2015 13:46:56 +0300 Subject: [PATCH] removed using `view.model.objects` --- rest_framework/filters.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rest_framework/filters.py b/rest_framework/filters.py index 743469f8f..1ef4c7fa0 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -101,18 +101,17 @@ class SearchFilter(BaseFilterBackend): orm_lookups = [self.construct_search(six.text_type(search_field)) for search_field in search_fields] - + and_queries = [] for search_term in self.get_search_terms(request): or_queries = [models.Q(**{orm_lookup: search_term}) for orm_lookup in orm_lookups] - queryset = queryset.filter(reduce(operator.or_, or_queries)) + and_queries.append(reduce(operator.or_, or_queries)) - if settings.DATABASES[queryset.db]["ENGINE"] != "django.db.backends.oracle": - queryset = queryset.distinct() + if settings.DATABASES[queryset.db]["ENGINE"] == "django.db.backends.oracle": + pk_list = queryset.filter(reduce(operator.and_, and_queries)).values_list('pk', flat=True) + return queryset.filter(pk__in=frozenset(pk_list)) else: - pk_list = queryset.values_list('pk', flat=True) - queryset = view.model.objects.filter(pk__in=set(pk_list)) - return queryset + return queryset.filter(reduce(operator.and_, and_queries)).distinct() class OrderingFilter(BaseFilterBackend):