Description
Is your proposal related to a problem?
This is a similar problem described in wagtail-nest/wagtail-modeladmin#21, but for snippets.
When you override SnippetViewSet.get_queryset(request)
, the resulting queryset is only used for the index view. This means that if you put certain filters to prevent users from accessing certain objects, the "detail" view e.g. edit, delete, inspect, etc. can still be accessed via the URL.
The documentation does mention that the get_queryset()
method override is for the index view, but for the reasons stated above, it would be nice if this extends to the other views as well.
Describe the solution you'd like
One way to achieve this would be to allow the queryset
to be defined as a class/instance attribute on those views (some of them that extend from Django likely support this already), then pass the SnippetViewSet.get_queryset
function down to the view as the queryset
, then update the view code to check if the queryset
is a callable. If so, call it with the request object, then use it to do the rest of the view logic.
Describe alternatives you've considered
Alternatively, just like ModelAdmin, we could leverage the fact that snippet models have the viewset accessible via model.snippet_viewset
, and use it directly in the view. However, this does mean that the view now "knows" about the existence of the viewset, which is undesirable as the viewset is a higher abstraction on top of the view. Not to mention that this doesn't sit well with our work on making snippets features more generic in #10740.
Metadata
Metadata
Assignees
Type
Projects
Status
Status