Skip to content

Pass the current request when initializing a filterset within a UI view #10816

Closed
@jeremystretch

Description

@jeremystretch

Proposed Changes

Currently, NetBox initializes django-filter FilterSets passing only the required data and queryset parameters, e.g.

if self.filterset:
    self.queryset = self.filterset(request.GET, self.queryset).qs

We can extend this to also pass the current request, which gets saved on the FilterSet instance:

if self.filterset:
    self.queryset = self.filterset(request.GET, self.queryset, request=request).qs

This should be applied to all occurrences of FitlerSet instantiation. (This already occurs for API views.)

Justification

Passing the current request to the FilterSet allows filters to reference additional context, such as the user making the request.

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: housekeepingChanges to the application which do not directly impact the end user

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions