Housekeeping: Use RestrictedQuerySet for default manager on base models

This commit is contained in:
jeremystretch 2021-11-11 15:04:22 -05:00
parent 834f68e6e4
commit d529c1b5b3
21 changed files with 7 additions and 108 deletions

View File

@ -7,7 +7,6 @@ from circuits.choices import *
from dcim.models import LinkTermination from dcim.models import LinkTermination
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import ChangeLoggedModel, OrganizationalModel, PrimaryModel from netbox.models import ChangeLoggedModel, OrganizationalModel, PrimaryModel
from utilities.querysets import RestrictedQuerySet
__all__ = ( __all__ = (
'Circuit', 'Circuit',
@ -35,8 +34,6 @@ class CircuitType(OrganizationalModel):
blank=True, blank=True,
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
@ -123,8 +120,6 @@ class Circuit(PrimaryModel):
null=True null=True
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'provider', 'type', 'status', 'tenant', 'install_date', 'commit_rate', 'description', 'provider', 'type', 'status', 'tenant', 'install_date', 'commit_rate', 'description',
] ]
@ -195,8 +190,6 @@ class CircuitTermination(ChangeLoggedModel, LinkTermination):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['circuit', 'term_side'] ordering = ['circuit', 'term_side']
unique_together = ['circuit', 'term_side'] unique_together = ['circuit', 'term_side']

View File

@ -59,8 +59,6 @@ class Provider(PrimaryModel):
to='tenancy.ContactAssignment' to='tenancy.ContactAssignment'
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact', 'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact',
] ]
@ -97,8 +95,6 @@ class ProviderNetwork(PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ('provider', 'name') ordering = ('provider', 'name')
constraints = ( constraints = (

View File

@ -14,7 +14,6 @@ from dcim.utils import decompile_path_node, object_to_path_node, path_node_to_ob
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import BigIDModel, PrimaryModel from netbox.models import BigIDModel, PrimaryModel
from utilities.fields import ColorField from utilities.fields import ColorField
from utilities.querysets import RestrictedQuerySet
from utilities.utils import to_meters from utilities.utils import to_meters
from .devices import Device from .devices import Device
from .device_components import FrontPort, RearPort from .device_components import FrontPort, RearPort
@ -116,8 +115,6 @@ class Cable(PrimaryModel):
null=True null=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['pk'] ordering = ['pk']
unique_together = ( unique_together = (

View File

@ -7,7 +7,6 @@ from dcim.constants import *
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import ChangeLoggedModel from netbox.models import ChangeLoggedModel
from utilities.fields import ColorField, NaturalOrderingField from utilities.fields import ColorField, NaturalOrderingField
from utilities.querysets import RestrictedQuerySet
from utilities.ordering import naturalize_interface from utilities.ordering import naturalize_interface
from .device_components import ( from .device_components import (
ConsolePort, ConsoleServerPort, DeviceBay, FrontPort, Interface, PowerOutlet, PowerPort, RearPort, ConsolePort, ConsoleServerPort, DeviceBay, FrontPort, Interface, PowerOutlet, PowerPort, RearPort,
@ -50,8 +49,6 @@ class ComponentTemplateModel(ChangeLoggedModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
abstract = True abstract = True

View File

@ -16,7 +16,6 @@ from netbox.models import PrimaryModel
from utilities.fields import ColorField, NaturalOrderingField from utilities.fields import ColorField, NaturalOrderingField
from utilities.mptt import TreeManager from utilities.mptt import TreeManager
from utilities.ordering import naturalize_interface from utilities.ordering import naturalize_interface
from utilities.querysets import RestrictedQuerySet
from utilities.query_functions import CollateAsChar from utilities.query_functions import CollateAsChar
from wireless.choices import * from wireless.choices import *
from wireless.utils import get_channel_attr from wireless.utils import get_channel_attr
@ -65,8 +64,6 @@ class ComponentModel(PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
abstract = True abstract = True

View File

@ -18,7 +18,6 @@ from netbox.config import ConfigItem
from netbox.models import OrganizationalModel, PrimaryModel from netbox.models import OrganizationalModel, PrimaryModel
from utilities.choices import ColorChoices from utilities.choices import ColorChoices
from utilities.fields import ColorField, NaturalOrderingField from utilities.fields import ColorField, NaturalOrderingField
from utilities.querysets import RestrictedQuerySet
from .device_components import * from .device_components import *
@ -59,8 +58,6 @@ class Manufacturer(OrganizationalModel):
to='tenancy.ContactAssignment' to='tenancy.ContactAssignment'
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
@ -137,8 +134,6 @@ class DeviceType(PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'manufacturer', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow', 'manufacturer', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow',
] ]
@ -379,8 +374,6 @@ class DeviceRole(OrganizationalModel):
blank=True, blank=True,
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
@ -431,8 +424,6 @@ class Platform(OrganizationalModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
@ -896,8 +887,6 @@ class VirtualChassis(PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
verbose_name_plural = 'virtual chassis' verbose_name_plural = 'virtual chassis'

View File

@ -8,7 +8,6 @@ from dcim.choices import *
from dcim.constants import * from dcim.constants import *
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import PrimaryModel from netbox.models import PrimaryModel
from utilities.querysets import RestrictedQuerySet
from utilities.validators import ExclusionValidator from utilities.validators import ExclusionValidator
from .device_components import LinkTermination, PathEndpoint from .device_components import LinkTermination, PathEndpoint
@ -49,8 +48,6 @@ class PowerPanel(PrimaryModel):
to='extras.ImageAttachment' to='extras.ImageAttachment'
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['site', 'name'] ordering = ['site', 'name']
unique_together = ['site', 'name'] unique_together = ['site', 'name']
@ -131,8 +128,6 @@ class PowerFeed(PrimaryModel, PathEndpoint, LinkTermination):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'power_panel', 'rack', 'status', 'type', 'mark_connected', 'supply', 'phase', 'voltage', 'amperage', 'power_panel', 'rack', 'status', 'type', 'mark_connected', 'supply', 'phase', 'voltage', 'amperage',
'max_utilization', 'available_power', 'max_utilization', 'available_power',

View File

@ -18,7 +18,6 @@ from netbox.config import get_config
from netbox.models import OrganizationalModel, PrimaryModel from netbox.models import OrganizationalModel, PrimaryModel
from utilities.choices import ColorChoices from utilities.choices import ColorChoices
from utilities.fields import ColorField, NaturalOrderingField from utilities.fields import ColorField, NaturalOrderingField
from utilities.querysets import RestrictedQuerySet
from utilities.utils import array_to_string from utilities.utils import array_to_string
from .device_components import PowerOutlet, PowerPort from .device_components import PowerOutlet, PowerPort
from .devices import Device from .devices import Device
@ -56,8 +55,6 @@ class RackRole(OrganizationalModel):
blank=True, blank=True,
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
@ -190,8 +187,6 @@ class Rack(PrimaryModel):
to='extras.ImageAttachment' to='extras.ImageAttachment'
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'site', 'location', 'tenant', 'status', 'role', 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'site', 'location', 'tenant', 'status', 'role', 'type', 'width', 'u_height', 'desc_units', 'outer_width',
'outer_depth', 'outer_unit', 'outer_depth', 'outer_unit',
@ -471,8 +466,6 @@ class RackReservation(PrimaryModel):
max_length=200 max_length=200
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['created', 'pk'] ordering = ['created', 'pk']

View File

@ -11,7 +11,6 @@ from dcim.fields import ASNField
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import NestedGroupModel, PrimaryModel from netbox.models import NestedGroupModel, PrimaryModel
from utilities.fields import NaturalOrderingField from utilities.fields import NaturalOrderingField
from utilities.querysets import RestrictedQuerySet
__all__ = ( __all__ = (
'Location', 'Location',
@ -259,8 +258,6 @@ class Site(PrimaryModel):
to='extras.ImageAttachment' to='extras.ImageAttachment'
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'status', 'region', 'group', 'tenant', 'facility', 'asn', 'time_zone', 'description', 'physical_address', 'status', 'region', 'group', 'tenant', 'facility', 'asn', 'time_zone', 'description', 'physical_address',
'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email', 'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email',

View File

@ -125,8 +125,6 @@ class Webhook(ChangeLoggedModel):
'Leave blank to use the system defaults.' 'Leave blank to use the system defaults.'
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
unique_together = ('payload_url', 'type_create', 'type_update', 'type_delete',) unique_together = ('payload_url', 'type_create', 'type_update', 'type_delete',)
@ -222,8 +220,6 @@ class CustomLink(ChangeLoggedModel):
help_text="Force link to open in a new window" help_text="Force link to open in a new window"
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['group_name', 'weight', 'name'] ordering = ['group_name', 'weight', 'name']
@ -268,8 +264,6 @@ class ExportTemplate(ChangeLoggedModel):
help_text="Download file as attachment" help_text="Download file as attachment"
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['content_type', 'name'] ordering = ['content_type', 'name']
unique_together = [ unique_together = [
@ -429,8 +423,6 @@ class JournalEntry(ChangeLoggedModel):
) )
comments = models.TextField() comments = models.TextField()
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ('-created',) ordering = ('-created',)
verbose_name_plural = 'journal entries' verbose_name_plural = 'journal entries'

View File

@ -7,7 +7,6 @@ from extras.utils import extras_features
from netbox.models import BigIDModel, ChangeLoggedModel from netbox.models import BigIDModel, ChangeLoggedModel
from utilities.choices import ColorChoices from utilities.choices import ColorChoices
from utilities.fields import ColorField from utilities.fields import ColorField
from utilities.querysets import RestrictedQuerySet
# #
@ -24,8 +23,6 @@ class Tag(ChangeLoggedModel, TagBase):
blank=True, blank=True,
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']

View File

@ -8,7 +8,6 @@ from extras.utils import extras_features
from netbox.models import ChangeLoggedModel, PrimaryModel from netbox.models import ChangeLoggedModel, PrimaryModel
from ipam.choices import * from ipam.choices import *
from ipam.constants import * from ipam.constants import *
from utilities.querysets import RestrictedQuerySet
__all__ = ( __all__ = (
'FHRPGroup', 'FHRPGroup',
@ -50,8 +49,6 @@ class FHRPGroup(PrimaryModel):
related_query_name='fhrpgroup' related_query_name='fhrpgroup'
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = ('protocol', 'auth_type', 'auth_key') clone_fields = ('protocol', 'auth_type', 'auth_key')
class Meta: class Meta:
@ -87,8 +84,6 @@ class FHRPGroupAssignment(ChangeLoggedModel):
) )
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = ('interface_type', 'interface_id') clone_fields = ('interface_type', 'interface_id')
class Meta: class Meta:

View File

@ -18,7 +18,6 @@ from ipam.managers import IPAddressManager
from ipam.querysets import PrefixQuerySet from ipam.querysets import PrefixQuerySet
from ipam.validators import DNSValidator from ipam.validators import DNSValidator
from netbox.config import get_config from netbox.config import get_config
from utilities.querysets import RestrictedQuerySet
from virtualization.models import VirtualMachine from virtualization.models import VirtualMachine
@ -57,8 +56,6 @@ class RIR(OrganizationalModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
verbose_name = 'RIR' verbose_name = 'RIR'
@ -100,8 +97,6 @@ class ASN(PrimaryModel):
null=True null=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['asn'] ordering = ['asn']
verbose_name = 'ASN' verbose_name = 'ASN'
@ -143,8 +138,6 @@ class Aggregate(PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'rir', 'tenant', 'date_added', 'description', 'rir', 'tenant', 'date_added', 'description',
] ]
@ -235,8 +228,6 @@ class Role(OrganizationalModel):
blank=True, blank=True,
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['weight', 'name'] ordering = ['weight', 'name']
@ -592,8 +583,6 @@ class IPRange(PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'vrf', 'tenant', 'status', 'role', 'description', 'vrf', 'tenant', 'status', 'role', 'description',
] ]

View File

@ -8,7 +8,6 @@ from extras.utils import extras_features
from ipam.choices import * from ipam.choices import *
from ipam.constants import * from ipam.constants import *
from netbox.models import PrimaryModel from netbox.models import PrimaryModel
from utilities.querysets import RestrictedQuerySet
from utilities.utils import array_to_string from utilities.utils import array_to_string
@ -65,8 +64,6 @@ class Service(PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ('protocol', 'ports', 'pk') # (protocol, port) may be non-unique ordering = ('protocol', 'ports', 'pk') # (protocol, port) may be non-unique

View File

@ -11,7 +11,6 @@ from ipam.choices import *
from ipam.constants import * from ipam.constants import *
from ipam.querysets import VLANQuerySet from ipam.querysets import VLANQuerySet
from netbox.models import OrganizationalModel, PrimaryModel from netbox.models import OrganizationalModel, PrimaryModel
from utilities.querysets import RestrictedQuerySet
from virtualization.models import VMInterface from virtualization.models import VMInterface
@ -52,8 +51,6 @@ class VLANGroup(OrganizationalModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ('name', 'pk') # Name may be non-unique ordering = ('name', 'pk') # Name may be non-unique
unique_together = [ unique_together = [

View File

@ -4,7 +4,6 @@ from django.urls import reverse
from extras.utils import extras_features from extras.utils import extras_features
from ipam.constants import * from ipam.constants import *
from netbox.models import PrimaryModel from netbox.models import PrimaryModel
from utilities.querysets import RestrictedQuerySet
__all__ = ( __all__ = (
@ -58,8 +57,6 @@ class VRF(PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'tenant', 'enforce_unique', 'description', 'tenant', 'enforce_unique', 'description',
] ]
@ -100,8 +97,6 @@ class RouteTarget(PrimaryModel):
null=True null=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']

View File

@ -11,6 +11,7 @@ from taggit.managers import TaggableManager
from extras.choices import ObjectChangeActionChoices from extras.choices import ObjectChangeActionChoices
from netbox.signals import post_clean from netbox.signals import post_clean
from utilities.mptt import TreeManager from utilities.mptt import TreeManager
from utilities.querysets import RestrictedQuerySet
from utilities.utils import serialize_object from utilities.utils import serialize_object
__all__ = ( __all__ = (
@ -169,6 +170,8 @@ class ChangeLoggedModel(ChangeLoggingMixin, CustomValidationMixin, BigIDModel):
""" """
Base model for all objects which support change logging. Base model for all objects which support change logging.
""" """
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
abstract = True abstract = True
@ -183,6 +186,8 @@ class PrimaryModel(ChangeLoggingMixin, CustomFieldsMixin, CustomValidationMixin,
content_type_field='assigned_object_type' content_type_field='assigned_object_type'
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
abstract = True abstract = True
@ -251,6 +256,8 @@ class OrganizationalModel(ChangeLoggingMixin, CustomFieldsMixin, CustomValidatio
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
abstract = True abstract = True
ordering = ('name',) ordering = ('name',)

View File

@ -7,7 +7,6 @@ from mptt.models import TreeForeignKey
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import ChangeLoggedModel, NestedGroupModel, OrganizationalModel, PrimaryModel from netbox.models import ChangeLoggedModel, NestedGroupModel, OrganizationalModel, PrimaryModel
from tenancy.choices import * from tenancy.choices import *
from utilities.querysets import RestrictedQuerySet
__all__ = ( __all__ = (
'ContactAssignment', 'ContactAssignment',
@ -69,8 +68,6 @@ class ContactRole(OrganizationalModel):
blank=True, blank=True,
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
@ -115,8 +112,6 @@ class Contact(PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'group', 'group',
] ]
@ -161,8 +156,6 @@ class ContactAssignment(ChangeLoggedModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = ('content_type', 'object_id') clone_fields = ('content_type', 'object_id')
class Meta: class Meta:

View File

@ -5,7 +5,6 @@ from mptt.models import TreeForeignKey
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import NestedGroupModel, PrimaryModel from netbox.models import NestedGroupModel, PrimaryModel
from utilities.querysets import RestrictedQuerySet
__all__ = ( __all__ = (
'Tenant', 'Tenant',
@ -80,8 +79,6 @@ class Tenant(PrimaryModel):
to='tenancy.ContactAssignment' to='tenancy.ContactAssignment'
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'group', 'description', 'group', 'description',
] ]

View File

@ -13,7 +13,6 @@ from netbox.models import OrganizationalModel, PrimaryModel
from utilities.fields import NaturalOrderingField from utilities.fields import NaturalOrderingField
from utilities.ordering import naturalize_interface from utilities.ordering import naturalize_interface
from utilities.query_functions import CollateAsChar from utilities.query_functions import CollateAsChar
from utilities.querysets import RestrictedQuerySet
from .choices import * from .choices import *
@ -48,8 +47,6 @@ class ClusterType(OrganizationalModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
@ -93,8 +90,6 @@ class ClusterGroup(OrganizationalModel):
to='tenancy.ContactAssignment' to='tenancy.ContactAssignment'
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
@ -158,8 +153,6 @@ class Cluster(PrimaryModel):
to='tenancy.ContactAssignment' to='tenancy.ContactAssignment'
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = [ clone_fields = [
'type', 'group', 'tenant', 'site', 'type', 'group', 'tenant', 'site',
] ]
@ -405,8 +398,6 @@ class VMInterface(PrimaryModel, BaseInterface):
related_query_name='+' related_query_name='+'
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
verbose_name = 'interface' verbose_name = 'interface'
ordering = ('virtual_machine', CollateAsChar('_name')) ordering = ('virtual_machine', CollateAsChar('_name'))

View File

@ -7,7 +7,6 @@ from dcim.choices import LinkStatusChoices
from dcim.constants import WIRELESS_IFACE_TYPES from dcim.constants import WIRELESS_IFACE_TYPES
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import BigIDModel, NestedGroupModel, PrimaryModel from netbox.models import BigIDModel, NestedGroupModel, PrimaryModel
from utilities.querysets import RestrictedQuerySet
from .choices import * from .choices import *
from .constants import * from .constants import *
@ -109,8 +108,6 @@ class WirelessLAN(WirelessAuthenticationBase, PrimaryModel):
blank=True blank=True
) )
objects = RestrictedQuerySet.as_manager()
class Meta: class Meta:
ordering = ('ssid', 'pk') ordering = ('ssid', 'pk')
verbose_name = 'Wireless LAN' verbose_name = 'Wireless LAN'
@ -171,8 +168,6 @@ class WirelessLink(WirelessAuthenticationBase, PrimaryModel):
null=True null=True
) )
objects = RestrictedQuerySet.as_manager()
clone_fields = ('ssid', 'status') clone_fields = ('ssid', 'status')
class Meta: class Meta: