Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Depercate DjangoFilterBackend
  • Loading branch information
lovelydinosaur committed Oct 20, 2016
commit 53421bdc927f64fd7dddb9229154c68a4d504cd3
10 changes: 5 additions & 5 deletions docs/api-guide/filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ The default filter backends may be set globally, using the `DEFAULT_FILTER_BACKE
You can also set the filter backends on a per-view, or per-viewset basis,
using the `GenericAPIView` class-based views.

import django_filters
from django.contrib.auth.models import User
from django_filters.rest_framework import DjangoFilterBackend
from myapp.serializers import UserSerializer
from rest_framework import generics

class UserListView(generics.ListAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
filter_backends = (DjangoFilterBackend,)
filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)

## Filtering and object lookups

Expand Down Expand Up @@ -191,7 +191,7 @@ For more advanced filtering requirements you can specify a `FilterSet` class tha
from myapp.serializers import ProductSerializer
from rest_framework import generics

class ProductFilter(django_filters.FilterSet):
class ProductFilter(django_filters.rest_framework.FilterSet):
min_price = django_filters.NumberFilter(name="price", lookup_expr='gte')
max_price = django_filters.NumberFilter(name="price", lookup_expr='lte')
class Meta:
Expand All @@ -218,7 +218,7 @@ filters using `Manufacturer` name. For example:
from myapp.serializers import ProductSerializer
from rest_framework import generics

class ProductFilter(django_filters.FilterSet):
class ProductFilter(django_filters.rest_framework.FilterSet):
class Meta:
model = Product
fields = ['category', 'in_stock', 'manufacturer__name']
Expand All @@ -234,7 +234,7 @@ This is nice, but it exposes the Django's double underscore convention as part o
from myapp.serializers import ProductSerializer
from rest_framework import generics

class ProductFilter(django_filters.FilterSet):
class ProductFilter(django_filters.rest_framework.FilterSet):
manufacturer = django_filters.CharFilter(name="manufacturer__name")

class Meta:
Expand Down
13 changes: 12 additions & 1 deletion rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ def get_schema_fields(self, view):
return []


class FilterSet(object):
def __new__(cls, *args, **kwargs):
warnings.warn(
"The built in 'rest_framework.filters.FilterSet' is pending deprecation. "
"You should use 'django_filters.rest_framework.FilterSet' instead.",
PendingDeprecationWarning
)
from django_filters.rest_framework import FilterSet
return FilterSet(*args, **kwargs)


class DjangoFilterBackend(BaseFilterBackend):
"""
A filter backend that uses django-filter.
Expand All @@ -47,7 +58,7 @@ def __new__(cls, *args, **kwargs):

warnings.warn(
"The built in 'rest_framework.filters.DjangoFilterBackend' is pending deprecation. "
"You should now use 'django_filters.rest_framework.DjangoFilterBackend' instead.",
"You should use 'django_filters.rest_framework.DjangoFilterBackend' instead.",
PendingDeprecationWarning
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def test_backend_deprecation(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, self.data)

self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
self.assertIn("'rest_framework.filters.DjangoFilterBackend' has been deprecated", str(w[-1].message))
self.assertTrue(issubclass(w[-1].category, PendingDeprecationWarning))
self.assertIn("'rest_framework.filters.DjangoFilterBackend' is pending deprecation.", str(w[-1].message))

@unittest.skipUnless(django_filters, 'django-filter not installed')
def test_no_df_deprecation(self):
Expand Down