From 4a2bad03c5ee56955b30fea09ad7dbd7c2818aec Mon Sep 17 00:00:00 2001 From: malinich Date: Fri, 5 Jun 2015 15:40:13 +0300 Subject: [PATCH 1/2] outdated method 'get_filter_backends' has been deleted from the documentation --- docs/api-guide/generic-views.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/docs/api-guide/generic-views.md b/docs/api-guide/generic-views.md index cb31f5f73..54d7cd96a 100644 --- a/docs/api-guide/generic-views.md +++ b/docs/api-guide/generic-views.md @@ -124,22 +124,6 @@ For example: Note that if your API doesn't include any object level permissions, you may optionally exclude the `self.check_object_permissions`, and simply return the object from the `get_object_or_404` lookup. -#### `get_filter_backends(self)` - -Returns the classes that should be used to filter the queryset. Defaults to returning the `filter_backends` attribute. - -May be overridden to provide more complex behavior with filters, such as using different (or even exclusive) lists of filter_backends depending on different criteria. - -For example: - - def get_filter_backends(self): - if "geo_route" in self.request.query_params: - return (GeoRouteFilter, CategoryFilter) - elif "geo_point" in self.request.query_params: - return (GeoPointFilter, CategoryFilter) - - return (CategoryFilter,) - #### `get_serializer_class(self)` Returns the class that should be used for the serializer. Defaults to returning the `serializer_class` attribute. From c80796ec040440edd92de9bd958c37cfd412067a Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Wed, 10 Jun 2015 23:32:52 +0200 Subject: [PATCH 2/2] Mention `filter_queryset` as an alternative to former `get_filter_backends` --- docs/api-guide/generic-views.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/api-guide/generic-views.md b/docs/api-guide/generic-views.md index 54d7cd96a..ac27c132f 100644 --- a/docs/api-guide/generic-views.md +++ b/docs/api-guide/generic-views.md @@ -124,6 +124,25 @@ For example: Note that if your API doesn't include any object level permissions, you may optionally exclude the `self.check_object_permissions`, and simply return the object from the `get_object_or_404` lookup. +#### `filter_queryset(self, queryset)` + +Given a queryset, filter it with whichever filter backends are in use, returning a new queryset. + +For example: + + def filter_queryset(self, queryset): + filter_backends = (CategoryFilter,) + + if 'geo_route' in self.request.query_params: + filter_backends = (GeoRouteFilter, CategoryFilter) + elif 'geo_point' in self.request.query_params: + filter_backends = (GeoPointFilter, CategoryFilter) + + for backend in list(filter_backends): + queryset = backend().filter_queryset(self.request, queryset, view=self) + + return queryset + #### `get_serializer_class(self)` Returns the class that should be used for the serializer. Defaults to returning the `serializer_class` attribute.