From 8608bd7d19c088c5e86032d36783e5bb7ec82494 Mon Sep 17 00:00:00 2001 From: Loic Teixeira Date: Mon, 2 Jul 2018 12:50:25 +1000 Subject: [PATCH] Add django-filter to dependencies DRF used to transparently import `django-filter` but it doesn't anymore in 3.7 (which is required by Wagtail 2.0), see https://github.com/encode/django-rest-framework/pull/5273. As a side effect, close #19. --- setup.py | 3 ++- wagtailmodelchoosers/views.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index e7d6aaf..ed382d9 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,8 @@ install_requires = [ - 'wagtail>=2.0b1' # Depends on Wagtail's Django and Django RestFramework depencencies + 'wagtail>=2.0b1', # Depends on Wagtail's Django and Django RestFramework depencencies + 'django-filter>=1.1.0,<2', ] # Testing dependencies diff --git a/wagtailmodelchoosers/views.py b/wagtailmodelchoosers/views.py index 8eb5337..1d57ef0 100644 --- a/wagtailmodelchoosers/views.py +++ b/wagtailmodelchoosers/views.py @@ -1,8 +1,10 @@ import requests from django.apps import apps from django.db.models import CharField, Q -from rest_framework import filters, serializers +from django_filters.rest_framework import DjangoFilterBackend +from rest_framework import serializers from rest_framework.authentication import BasicAuthentication, SessionAuthentication +from rest_framework.filters import SearchFilter from rest_framework.mixins import ListModelMixin from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -20,7 +22,7 @@ class ModelView(ListModelMixin, GenericViewSet): pagination_class = GenericModelPaginator authentication_classes = (SessionAuthentication, BasicAuthentication) permission_classes = (IsAuthenticated,) - filter_backends = (filters.DjangoFilterBackend, filters.SearchFilter,) + filter_backends = (DjangoFilterBackend, SearchFilter,) def get_params(self): return self.request.parser_context.get('kwargs') @@ -100,7 +102,7 @@ def build_serializer(self, cls, model_name): class RemoteResourceView(ViewSet): authentication_classes = (SessionAuthentication, BasicAuthentication) permission_classes = (IsAuthenticated,) - filter_backends = (filters.DjangoFilterBackend, filters.SearchFilter,) + filter_backends = (DjangoFilterBackend, SearchFilter,) http_method_names = ('get', 'head', 'options') def get_params(self):