Update all utility views to specify a QuerySet instead of a model #3673

Closed
opened 2025-12-29 18:30:32 +01:00 by adam · 1 comment
Owner

Originally created by @jeremystretch on GitHub (May 11, 2020).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

Modify all existing utility view subclasses for object creation, deletion, etc. to specify a base QuerySet instead of a model class. For example:

class SiteCreateView(PermissionRequiredMixin, ObjectEditView):
    model = Site

becomes:

class SiteCreateView(PermissionRequiredMixin, ObjectEditView):
    queryset = Site.objects.all()

The utility views themselves will be adjusted to work with a QuerySet. For example:

get_object_or_404(self.model, pk=kwargs['pk'])

becomes:

get_object_or_404(self.queryset, pk=kwargs['pk'])

Justification

  1. This allows for opportunistic prefetching of related fields, which should yield modest performance gains.
  2. This has been identified as a blocker for #554. Initializing each view with a QuerySet provides a common interface for a mixin class to manipulate the object set based on the user's permissions.
Originally created by @jeremystretch on GitHub (May 11, 2020). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes Modify all existing utility view subclasses for object creation, deletion, etc. to specify a base QuerySet instead of a model class. For example: ```python class SiteCreateView(PermissionRequiredMixin, ObjectEditView): model = Site ``` becomes: ```python class SiteCreateView(PermissionRequiredMixin, ObjectEditView): queryset = Site.objects.all() ``` The utility views themselves will be adjusted to work with a QuerySet. For example: ```python get_object_or_404(self.model, pk=kwargs['pk']) ``` becomes: ```python get_object_or_404(self.queryset, pk=kwargs['pk']) ``` ### Justification 1. This allows for opportunistic prefetching of related fields, which should yield modest performance gains. 2. This has been identified as a blocker for #554. Initializing each view with a QuerySet provides a common interface for a mixin class to manipulate the object set based on the user's permissions.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 18:30:32 +01:00
adam closed this issue 2025-12-29 18:30:32 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 2, 2020):

This work has been completed under #554.

@jeremystretch commented on GitHub (Jun 2, 2020): This work has been completed under #554.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3673