mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-19 21:13:32 +03:00
parent
271c4c5920
commit
0ac20a3d8e
|
@ -160,13 +160,13 @@ Or add the filter backend to an individual View or ViewSet.
|
||||||
...
|
...
|
||||||
filter_backends = (DjangoFilterBackend,)
|
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):
|
class ProductList(generics.ListAPIView):
|
||||||
queryset = Product.objects.all()
|
queryset = Product.objects.all()
|
||||||
serializer_class = ProductSerializer
|
serializer_class = ProductSerializer
|
||||||
filter_backends = (DjangoFilterBackend,)
|
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:
|
This will automatically create a `FilterSet` class for the given fields, and will allow you to make requests such as:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user