diff --git a/rest_framework/filters.py b/rest_framework/filters.py index 17e6975eb4..c48504957c 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -139,11 +139,9 @@ def to_html(self, request, queryset, view): if not getattr(view, 'search_fields', None): return '' - term = self.get_search_terms(request) - term = term[0] if term else '' context = { 'param': self.search_param, - 'term': term + 'term': request.query_params.get(self.search_param, ''), } template = loader.get_template(self.template) return template.render(context) diff --git a/tests/test_filters.py b/tests/test_filters.py index 37ae4c7cf3..2a22e30f97 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -225,6 +225,23 @@ def as_sql(self, compiler, connection): {'id': 2, 'title': 'zz', 'text': 'bcd'}, ] + def test_search_field_with_multiple_words(self): + class SearchListView(generics.ListAPIView): + queryset = SearchFilterModel.objects.all() + serializer_class = SearchFilterSerializer + filter_backends = (filters.SearchFilter,) + search_fields = ('title', 'text') + + search_query = 'foo bar,baz' + view = SearchListView() + request = factory.get('/', {'search': search_query}) + request = view.initialize_request(request) + + rendered_search_field = filters.SearchFilter().to_html( + request=request, queryset=view.queryset, view=view + ) + assert search_query in rendered_search_field + class AttributeModel(models.Model): label = models.CharField(max_length=32) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy