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

Closed
opened 2025-12-29 20:20:19 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Nov 2, 2022).

Originally assigned to: @jeremystretch on GitHub.

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.

Originally created by @jeremystretch on GitHub (Nov 2, 2022). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes Currently, NetBox initializes [django-filter]() FilterSets passing only the required data and queryset parameters, e.g. ```python 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: ```python 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.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 20:20:19 +01:00
adam closed this issue 2025-12-29 20:20:19 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7190