diff --git a/django_filters/views.py b/django_filters/views.py index c24f9aba..5d81760f 100644 --- a/django_filters/views.py +++ b/django_filters/views.py @@ -62,6 +62,14 @@ def get_filterset_kwargs(self, filterset_class): ) args = (filterset_class.__name__, self.__class__.__name__) raise ImproperlyConfigured(msg % args) + else: + self.model = filterset_class._meta.model + kwargs.update( + { + "queryset": self.get_queryset(), + } + ) + return kwargs def get_strict(self): diff --git a/tests/test_views.py b/tests/test_views.py index 98d84797..b23f89ba 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -120,7 +120,21 @@ def test_view_with_unbound_filter_form_returns_initial_queryset(self): self.assertEqual(response.status_code, 200) self.assertEqual(titles, ["Snowcrash"]) - + + def test_get_queryset_works_without_explicit_model(self): + + class TestView(FilterView): + filterset_class = filterset_factory(Book) + def get_queryset(self): + qs= super().get_queryset() + qs=qs.filter(title="Snowcrash") + return qs + + factory = RequestFactory() + request = factory.get(self.base_url) + view = TestView.as_view() + response = view(request) + assert response.context_data["object_list"].count() == 1 class GenericFunctionalViewTests(GenericViewTestCase): base_url = "/books-legacy/"