mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
Merge pull request #5117 from rpkilby/fix-filter-backend
Fix DjangoFilterBackend mro
This commit is contained in:
commit
69b0ac52c2
|
@ -1,6 +1,6 @@
|
|||
# Optional packages which may be used with REST framework.
|
||||
markdown==2.6.4
|
||||
django-guardian==1.4.8
|
||||
django-filter==1.0.0
|
||||
django-filter==1.0.2
|
||||
coreapi==2.2.4
|
||||
coreschema==0.0.4
|
||||
|
|
|
@ -50,12 +50,17 @@ if django_filters:
|
|||
DeprecationWarning
|
||||
)
|
||||
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(BaseFilterBackend):
|
||||
|
||||
class DjangoFilterBackend(DFBase):
|
||||
"""
|
||||
A filter backend that uses django-filter.
|
||||
"""
|
||||
|
@ -69,9 +74,7 @@ class DjangoFilterBackend(BaseFilterBackend):
|
|||
DeprecationWarning
|
||||
)
|
||||
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
|
||||
return DjangoFilterBackend(*args, **kwargs)
|
||||
return super(DjangoFilterBackend, cls).__new__(cls, *args, **kwargs)
|
||||
|
||||
|
||||
class SearchFilter(BaseFilterBackend):
|
||||
|
|
|
@ -201,6 +201,21 @@ class IntegrationTestFiltering(CommonFilteringTestCase):
|
|||
assert response.data == self.data
|
||||
assert len(w) == 0
|
||||
|
||||
@unittest.skipUnless(django_filters, 'django-filter not installed')
|
||||
def test_backend_mro(self):
|
||||
class CustomBackend(filters.DjangoFilterBackend):
|
||||
def filter_queryset(self, request, queryset, view):
|
||||
assert False, "custom filter_queryset should run"
|
||||
|
||||
class DFFilterFieldsRootView(FilterFieldsRootView):
|
||||
filter_backends = (CustomBackend,)
|
||||
|
||||
view = DFFilterFieldsRootView.as_view()
|
||||
request = factory.get('/')
|
||||
|
||||
with pytest.raises(AssertionError, message="custom filter_queryset should run"):
|
||||
view(request).render()
|
||||
|
||||
@unittest.skipUnless(django_filters, 'django-filter not installed')
|
||||
def test_get_filtered_fields_root_view(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user