Skip to content

Remove DjangoFilterBackend #5273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 0 additions & 7 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,6 @@ def value_from_object(field, obj):
coreschema = None


# django-filter is optional
try:
import django_filters
except ImportError:
django_filters = None


# django-crispy-forms is optional
try:
import crispy_forms
Expand Down
41 changes: 1 addition & 40 deletions rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from __future__ import unicode_literals

import operator
import warnings
from functools import reduce

from django.core.exceptions import ImproperlyConfigured
Expand All @@ -18,7 +17,7 @@
from django.utils.translation import ugettext_lazy as _

from rest_framework.compat import (
coreapi, coreschema, distinct, django_filters, guardian, template_render
coreapi, coreschema, distinct, guardian, template_render
)
from rest_framework.settings import api_settings

Expand All @@ -40,44 +39,6 @@ def get_schema_fields(self, view):
return []


if django_filters:
from django_filters.rest_framework.filterset import FilterSet as DFFilterSet

class FilterSet(DFFilterSet):
def __init__(self, *args, **kwargs):
warnings.warn(
"The built in 'rest_framework.filters.FilterSet' is deprecated. "
"You should use 'django_filters.rest_framework.FilterSet' instead.",
DeprecationWarning, stacklevel=2
)
return super(FilterSet, self).__init__(*args, **kwargs)

DFBase = django_filters.rest_framework.DjangoFilterBackend

else:
def FilterSet():
assert False, 'django-filter must be installed to use the `FilterSet` class'

DFBase = BaseFilterBackend


class DjangoFilterBackend(DFBase):
"""
A filter backend that uses django-filter.
"""
def __new__(cls, *args, **kwargs):
assert django_filters, 'Using DjangoFilterBackend, but django-filter is not installed'
assert django_filters.VERSION >= (0, 15, 3), 'django-filter 0.15.3 and above is required'

warnings.warn(
"The built in 'rest_framework.filters.DjangoFilterBackend' is deprecated. "
"You should use 'django_filters.rest_framework.DjangoFilterBackend' instead.",
DeprecationWarning, stacklevel=2
)

return super(DjangoFilterBackend, cls).__new__(cls, *args, **kwargs)


class SearchFilter(BaseFilterBackend):
# The URL query parameter used for the search.
search_param = api_settings.SEARCH_PARAM
Expand Down
9 changes: 0 additions & 9 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ class BasicModel(RESTFrameworkModel):
)


class BaseFilterableItem(RESTFrameworkModel):
text = models.CharField(max_length=100)


class FilterableItem(BaseFilterableItem):
decimal = models.DecimalField(max_digits=4, decimal_places=2)
date = models.DateField()


# Models for relations tests
# ManyToMany
class ManyToManyTarget(RESTFrameworkModel):
Expand Down
Loading