Model is not set on the view, not allowing the `MultipleObjectMixin`s default `get_queryset` to be called
yaakovLowenstein opened this issue · 8 comments
The issue is that because the model is never set on the view from the meta of the filterset_class
the default get_queryset
cannot be called.
The use case for this would be a call to super().get_queryset
from a view that inherits from FilterView
.
django-filter/django_filters/views.py
Line 123 in 4a3eb8b
If you'd like to explain a bit more maybe there's something here to help with, but the description is a bit terse as it is.
yes, sorry. In middle of submitting a PR as I thought it would be hard to explain but I think the PR will make it clearer
This should solve the issue #1682
@carltongibson does the PR help understand the issue. I was hoping the test would provide some clarity about it. In summary, the issue is that you cannot call super.get_queryset()
from a FilterView
.
I'd expect you to set model
as you would for ≈ any view extending MultipleObjectMixin
So in your test case:
class TestView(FilterView):
model = Book
...
That would solve the issue, however I think what's a little confusing is that django-filters makes it so that you do not need to set the model because its already set on the filterset as demonstrated here,
django-filter/django_filters/views.py
Lines 48 to 57 in 4a3eb8b
If the model is not defined resulting in an exception, it's caught because as the comment says, you do not need the model because you can get it form the filterset. Therefore why not set the model using the filterset's model.
Also because it catches the exception and ignores it, it actually hides the issue I describe above when you try calling super().get_queryset
.
Hey, wanted to follow up here. Any thoughts on this?
I could try to clarify more of what I'm saying isn't making sense.
Hi, yes. As per my previous reply, you're meant to set model
on your view.
If you want to add this fallback in your own project you're welcome, but it's not a change I want to add here. Thanks.