From 0ac20a3d8eb565f1845e2c9beeeb02b296526749 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Mon, 21 Jan 2019 21:00:54 +0100 Subject: [PATCH] Updated filtering docs to use `filterset_fields`. (#6415) Closes #6411. --- docs/api-guide/filtering.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api-guide/filtering.md b/docs/api-guide/filtering.md index 84c6d8d63..1a04ad5e3 100644 --- a/docs/api-guide/filtering.md +++ b/docs/api-guide/filtering.md @@ -160,13 +160,13 @@ Or add the filter backend to an individual View or ViewSet. ... filter_backends = (DjangoFilterBackend,) -If all you need is simple equality-based filtering, you can set a `filter_fields` attribute on the view, or viewset, listing the set of fields you wish to filter against. +If all you need is simple equality-based filtering, you can set a `filterset_fields` attribute on the view, or viewset, listing the set of fields you wish to filter against. class ProductList(generics.ListAPIView): queryset = Product.objects.all() serializer_class = ProductSerializer filter_backends = (DjangoFilterBackend,) - filter_fields = ('category', 'in_stock') + filterset_fields = ('category', 'in_stock') This will automatically create a `FilterSet` class for the given fields, and will allow you to make requests such as: @@ -188,7 +188,7 @@ When in use, the browsable API will include a `SearchFilter` control: The `SearchFilter` class will only be applied if the view has a `search_fields` attribute set. The `search_fields` attribute should be a list of names of text type fields on the model, such as `CharField` or `TextField`. from rest_framework import filters - + class UserListView(generics.ListAPIView): queryset = User.objects.all() serializer_class = UserSerializer