Skip to content

Commit ac7b20c

Browse files
SrdjanCosicPricacarltongibson
authored andcommitted
Fix get_search_fields example (encode#6487)
1 parent 0ab527a commit ac7b20c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

docs/api-guide/filtering.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,13 @@ By default, the search parameter is named `'search`', but this may be overridden
220220

221221
To dynamically change search fields based on request content, it's possible to subclass the `SearchFilter` and override the `get_search_fields()` function. For example, the following subclass will only search on `title` if the query parameter `title_only` is in the request:
222222

223-
class CustomSearchFilter(self, view, request):
224-
if request.query_params.get('title_only'):
225-
return ('title',)
226-
return super(CustomSearchFilter, self).get_search_fields(view, request)
223+
from rest_framework import filters
224+
225+
class CustomSearchFilter(filters.SearchFilter):
226+
def get_search_fields(self, view, request):
227+
if request.query_params.get('title_only'):
228+
return ('title',)
229+
return super(CustomSearchFilter, self).get_search_fields(view, request)
227230

228231
For more details, see the [Django documentation][search-django-admin].
229232

0 commit comments

Comments
 (0)