فهرست منبع

Housekeeping: Use RestrictedQuerySet for default manager on base models

jeremystretch 4 سال پیش
والد
کامیت
d529c1b5b3

+ 0 - 7
netbox/circuits/models/circuits.py

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

+ 0 - 4
netbox/circuits/models/providers.py

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

+ 0 - 3
netbox/dcim/models/cables.py

@@ -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 netbox.models import BigIDModel, PrimaryModel
 from utilities.fields import ColorField
-from utilities.querysets import RestrictedQuerySet
 from utilities.utils import to_meters
 from .devices import Device
 from .device_components import FrontPort, RearPort
@@ -116,8 +115,6 @@ class Cable(PrimaryModel):
         null=True
     )
 
-    objects = RestrictedQuerySet.as_manager()
-
     class Meta:
         ordering = ['pk']
         unique_together = (

+ 0 - 3
netbox/dcim/models/device_component_templates.py

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

+ 0 - 3
netbox/dcim/models/device_components.py

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

+ 0 - 11
netbox/dcim/models/devices.py

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

+ 0 - 5
netbox/dcim/models/power.py

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

+ 0 - 7
netbox/dcim/models/racks.py

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

+ 0 - 3
netbox/dcim/models/sites.py

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

+ 0 - 8
netbox/extras/models/models.py

@@ -125,8 +125,6 @@ class Webhook(ChangeLoggedModel):
                   'Leave blank to use the system defaults.'
     )
 
-    objects = RestrictedQuerySet.as_manager()
-
     class Meta:
         ordering = ('name',)
         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"
     )
 
-    objects = RestrictedQuerySet.as_manager()
-
     class Meta:
         ordering = ['group_name', 'weight', 'name']
 
@@ -268,8 +264,6 @@ class ExportTemplate(ChangeLoggedModel):
         help_text="Download file as attachment"
     )
 
-    objects = RestrictedQuerySet.as_manager()
-
     class Meta:
         ordering = ['content_type', 'name']
         unique_together = [
@@ -429,8 +423,6 @@ class JournalEntry(ChangeLoggedModel):
     )
     comments = models.TextField()
 
-    objects = RestrictedQuerySet.as_manager()
-
     class Meta:
         ordering = ('-created',)
         verbose_name_plural = 'journal entries'

+ 0 - 3
netbox/extras/models/tags.py

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

+ 0 - 5
netbox/ipam/models/fhrp.py

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

+ 0 - 11
netbox/ipam/models/ip.py

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

+ 0 - 3
netbox/ipam/models/services.py

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

+ 0 - 3
netbox/ipam/models/vlans.py

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

+ 0 - 5
netbox/ipam/models/vrfs.py

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

+ 7 - 0
netbox/netbox/models.py

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

+ 0 - 7
netbox/tenancy/models/contacts.py

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

+ 0 - 3
netbox/tenancy/models/tenants.py

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

+ 0 - 9
netbox/virtualization/models.py

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

+ 0 - 5
netbox/wireless/models.py

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