Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed using view.model.objects
  • Loading branch information
trollknurr committed May 15, 2015
commit de95598a1ed7f1b609b9dbc6415655be65fae4a8
13 changes: 6 additions & 7 deletions rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,17 @@ def filter_queryset(self, request, queryset, view):

orm_lookups = [self.construct_search(six.text_type(search_field))
for search_field in search_fields]

and_queries = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand the motivation here - feels more obscure after this change rather than more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't sure, if calling queryset.filter(pk_in=set(pk_list)) will make duplications go away, as they pk still will be in pk_list. I want to filter original queryset by pk_list.
When we call filter with multiple kwargs or several times on one queryset it is equal to logical and.

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):
Expand Down