You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The list of projects displayed is not actually filtered. While PermissionRequiredMixin.has_permission() is able to construct self.filtered_queryset, this filtered queryset is not called by the view rendering process because DetailProjList's get_queryset() method masks BasePermissionRequiredMixin's get_queryset() method.
It seems filtered querysets only work if the desired get_queryset() is only inherited via a mixin or a parent class and not declared in the view class itself.
The text was updated successfully, but these errors were encountered:
Let me think about this. I usually think of get_queryset as one of Django's DO WHAT I SAY methods, in the sense that, if you override it in a base view class, you are saying very clearly what you want the queryset to be, irrespective of whatever else is going on. I don't know if that's the right way to think of it.
What's the use case for this anyway? I don't think there are any instances of this in the current platform code.
I encountered this during my current coding. I wanted to override the get_queryset of a mixin, which returns a list of resources attached to the project, to instead return all resources in a project (whether attached to the project or not) in one particular view. To avoid this bug, I ended up just modifying the mixin itself to behave differently based on a new view class attribute.
Of course I can't do that if the mixin is not my code, so a workaround is to create a wrapper parent class, but that sounds like a kludge.
A view that has both
permission_filter_queryset
andget_queryset()
in the same class definition will fail to filter the queryset.For example, if I have the following view class definition:
The list of projects displayed is not actually filtered. While
PermissionRequiredMixin.has_permission()
is able to constructself.filtered_queryset
, this filtered queryset is not called by the view rendering process becauseDetailProjList
'sget_queryset()
method masksBasePermissionRequiredMixin
'sget_queryset()
method.It seems filtered querysets only work if the desired
get_queryset()
is only inherited via a mixin or a parent class and not declared in the view class itself.The text was updated successfully, but these errors were encountered: