From ac7b20cca2f7189f44fd3b86a9339d8f1763f17a Mon Sep 17 00:00:00 2001 From: SrdjanCosicPrica Date: Mon, 4 Mar 2019 14:46:14 +0100 Subject: [PATCH] Fix get_search_fields example (#6487) --- docs/api-guide/filtering.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/api-guide/filtering.md b/docs/api-guide/filtering.md index aff267818..8a500f386 100644 --- a/docs/api-guide/filtering.md +++ b/docs/api-guide/filtering.md @@ -220,10 +220,13 @@ By default, the search parameter is named `'search`', but this may be overridden 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: - class CustomSearchFilter(self, view, request): - if request.query_params.get('title_only'): - return ('title',) - return super(CustomSearchFilter, self).get_search_fields(view, request) + from rest_framework import filters + + class CustomSearchFilter(filters.SearchFilter): + def get_search_fields(self, view, request): + if request.query_params.get('title_only'): + return ('title',) + return super(CustomSearchFilter, self).get_search_fields(view, request) For more details, see the [Django documentation][search-django-admin].