1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Declare TaggableManager on PrimaryModel base class

This commit is contained in:
Jeremy Stretch
2021-03-10 14:32:50 -05:00
parent 20f60cd99d
commit fc5bb966f0
16 changed files with 11 additions and 66 deletions

View File

@ -1,10 +1,9 @@
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from taggit.managers import TaggableManager
from dcim.fields import ASNField from dcim.fields import ASNField
from dcim.models import CableTermination, PathEndpoint from dcim.models import CableTermination, PathEndpoint
from extras.models import ObjectChange, TaggedItem from extras.models import ObjectChange
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import BigIDModel, ChangeLoggedModel, OrganizationalModel, PrimaryModel from netbox.models import BigIDModel, ChangeLoggedModel, OrganizationalModel, PrimaryModel
from utilities.querysets import RestrictedQuerySet from utilities.querysets import RestrictedQuerySet
@ -60,7 +59,6 @@ class Provider(PrimaryModel):
comments = models.TextField( comments = models.TextField(
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
@ -184,7 +182,6 @@ class Circuit(PrimaryModel):
) )
objects = CircuitQuerySet.as_manager() objects = CircuitQuerySet.as_manager()
tags = TaggableManager(through=TaggedItem)
csv_headers = [ csv_headers = [
'cid', 'provider', 'type', 'status', 'tenant', 'install_date', 'commit_rate', 'description', 'comments', 'cid', 'provider', 'type', 'status', 'tenant', 'install_date', 'commit_rate', 'description', 'comments',

View File

@ -6,13 +6,11 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import models from django.db import models
from django.db.models import Sum from django.db.models import Sum
from django.urls import reverse from django.urls import reverse
from taggit.managers import TaggableManager
from dcim.choices import * from dcim.choices import *
from dcim.constants import * from dcim.constants import *
from dcim.fields import PathField from dcim.fields import PathField
from dcim.utils import decompile_path_node, object_to_path_node, path_node_to_object from dcim.utils import decompile_path_node, object_to_path_node, path_node_to_object
from extras.models import TaggedItem
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
@ -108,7 +106,6 @@ class Cable(PrimaryModel):
blank=True, blank=True,
null=True null=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -6,12 +6,10 @@ from django.db import models
from django.db.models import Sum from django.db.models import Sum
from django.urls import reverse from django.urls import reverse
from mptt.models import MPTTModel, TreeForeignKey from mptt.models import MPTTModel, TreeForeignKey
from taggit.managers import TaggableManager
from dcim.choices import * from dcim.choices import *
from dcim.constants import * from dcim.constants import *
from dcim.fields import MACAddressField from dcim.fields import MACAddressField
from extras.models import TaggedItem
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import PrimaryModel from netbox.models import PrimaryModel
from utilities.fields import NaturalOrderingField from utilities.fields import NaturalOrderingField
@ -227,7 +225,6 @@ class ConsolePort(ComponentModel, CableTermination, PathEndpoint):
null=True, null=True,
help_text='Port speed in bits per second' help_text='Port speed in bits per second'
) )
tags = TaggableManager(through=TaggedItem)
csv_headers = ['device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description'] csv_headers = ['device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description']
@ -271,7 +268,6 @@ class ConsoleServerPort(ComponentModel, CableTermination, PathEndpoint):
null=True, null=True,
help_text='Port speed in bits per second' help_text='Port speed in bits per second'
) )
tags = TaggableManager(through=TaggedItem)
csv_headers = ['device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description'] csv_headers = ['device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description']
@ -321,7 +317,6 @@ class PowerPort(ComponentModel, CableTermination, PathEndpoint):
validators=[MinValueValidator(1)], validators=[MinValueValidator(1)],
help_text="Allocated power draw (watts)" help_text="Allocated power draw (watts)"
) )
tags = TaggableManager(through=TaggedItem)
csv_headers = [ csv_headers = [
'device', 'name', 'label', 'type', 'mark_connected', 'maximum_draw', 'allocated_draw', 'description', 'device', 'name', 'label', 'type', 'mark_connected', 'maximum_draw', 'allocated_draw', 'description',
@ -434,7 +429,6 @@ class PowerOutlet(ComponentModel, CableTermination, PathEndpoint):
blank=True, blank=True,
help_text="Phase (for three-phase feeds)" help_text="Phase (for three-phase feeds)"
) )
tags = TaggableManager(through=TaggedItem)
csv_headers = ['device', 'name', 'label', 'type', 'mark_connected', 'power_port', 'feed_leg', 'description'] csv_headers = ['device', 'name', 'label', 'type', 'mark_connected', 'power_port', 'feed_leg', 'description']
@ -568,7 +562,6 @@ class Interface(ComponentModel, BaseInterface, CableTermination, PathEndpoint):
object_id_field='assigned_object_id', object_id_field='assigned_object_id',
related_query_name='interface' related_query_name='interface'
) )
tags = TaggableManager(through=TaggedItem)
csv_headers = [ csv_headers = [
'device', 'name', 'label', 'parent', 'lag', 'type', 'enabled', 'mark_connected', 'mac_address', 'mtu', 'device', 'name', 'label', 'parent', 'lag', 'type', 'enabled', 'mark_connected', 'mac_address', 'mtu',
@ -705,7 +698,6 @@ class FrontPort(ComponentModel, CableTermination):
MaxValueValidator(REARPORT_POSITIONS_MAX) MaxValueValidator(REARPORT_POSITIONS_MAX)
] ]
) )
tags = TaggableManager(through=TaggedItem)
csv_headers = [ csv_headers = [
'device', 'name', 'label', 'type', 'mark_connected', 'rear_port', 'rear_port_position', 'description', 'device', 'name', 'label', 'type', 'mark_connected', 'rear_port', 'rear_port_position', 'description',
@ -766,7 +758,6 @@ class RearPort(ComponentModel, CableTermination):
MaxValueValidator(REARPORT_POSITIONS_MAX) MaxValueValidator(REARPORT_POSITIONS_MAX)
] ]
) )
tags = TaggableManager(through=TaggedItem)
csv_headers = ['device', 'name', 'label', 'type', 'mark_connected', 'positions', 'description'] csv_headers = ['device', 'name', 'label', 'type', 'mark_connected', 'positions', 'description']
@ -816,7 +807,6 @@ class DeviceBay(ComponentModel):
blank=True, blank=True,
null=True null=True
) )
tags = TaggableManager(through=TaggedItem)
csv_headers = ['device', 'name', 'label', 'installed_device', 'description'] csv_headers = ['device', 'name', 'label', 'installed_device', 'description']
@ -909,8 +899,6 @@ class InventoryItem(MPTTModel, ComponentModel):
help_text='This item was automatically discovered' help_text='This item was automatically discovered'
) )
tags = TaggableManager(through=TaggedItem)
objects = TreeManager() objects = TreeManager()
csv_headers = [ csv_headers = [

View File

@ -9,11 +9,10 @@ from django.db import models
from django.db.models import F, ProtectedError from django.db.models import F, ProtectedError
from django.urls import reverse from django.urls import reverse
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from taggit.managers import TaggableManager
from dcim.choices import * from dcim.choices import *
from dcim.constants import * from dcim.constants import *
from extras.models import ConfigContextModel, TaggedItem from extras.models import ConfigContextModel
from extras.querysets import ConfigContextModelQuerySet from extras.querysets import ConfigContextModelQuerySet
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import OrganizationalModel, PrimaryModel from netbox.models import OrganizationalModel, PrimaryModel
@ -136,7 +135,6 @@ class DeviceType(PrimaryModel):
comments = models.TextField( comments = models.TextField(
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
@ -601,7 +599,6 @@ class Device(PrimaryModel, ConfigContextModel):
object_id_field='assigned_object_id', object_id_field='assigned_object_id',
related_query_name='device' related_query_name='device'
) )
tags = TaggableManager(through=TaggedItem)
objects = ConfigContextModelQuerySet.as_manager() objects = ConfigContextModelQuerySet.as_manager()
@ -916,7 +913,6 @@ class VirtualChassis(PrimaryModel):
max_length=30, max_length=30,
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -2,11 +2,9 @@ from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from taggit.managers import TaggableManager
from dcim.choices import * from dcim.choices import *
from dcim.constants import * from dcim.constants import *
from extras.models import TaggedItem
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.querysets import RestrictedQuerySet
@ -41,7 +39,6 @@ class PowerPanel(PrimaryModel):
name = models.CharField( name = models.CharField(
max_length=100 max_length=100
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
@ -133,7 +130,6 @@ class PowerFeed(PrimaryModel, PathEndpoint, CableTermination):
comments = models.TextField( comments = models.TextField(
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -11,12 +11,10 @@ from django.db import models
from django.db.models import Count, Sum from django.db.models import Count, Sum
from django.urls import reverse from django.urls import reverse
from mptt.models import TreeForeignKey from mptt.models import TreeForeignKey
from taggit.managers import TaggableManager
from dcim.choices import * from dcim.choices import *
from dcim.constants import * from dcim.constants import *
from dcim.elevations import RackElevationSVG from dcim.elevations import RackElevationSVG
from extras.models import TaggedItem
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import NestedGroupModel, OrganizationalModel, PrimaryModel from netbox.models import NestedGroupModel, OrganizationalModel, PrimaryModel
from utilities.choices import ColorChoices from utilities.choices import ColorChoices
@ -251,7 +249,6 @@ class Rack(PrimaryModel):
images = GenericRelation( images = GenericRelation(
to='extras.ImageAttachment' to='extras.ImageAttachment'
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
@ -558,7 +555,6 @@ class RackReservation(PrimaryModel):
description = models.CharField( description = models.CharField(
max_length=200 max_length=200
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -2,13 +2,11 @@ from django.contrib.contenttypes.fields import GenericRelation
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from mptt.models import TreeForeignKey from mptt.models import TreeForeignKey
from taggit.managers import TaggableManager
from timezone_field import TimeZoneField from timezone_field import TimeZoneField
from dcim.choices import * from dcim.choices import *
from dcim.constants import * from dcim.constants import *
from dcim.fields import ASNField from dcim.fields import ASNField
from extras.models import TaggedItem
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
@ -232,7 +230,6 @@ class Site(PrimaryModel):
images = GenericRelation( images = GenericRelation(
to='extras.ImageAttachment' to='extras.ImageAttachment'
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -6,10 +6,8 @@ from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.db.models import F from django.db.models import F
from django.urls import reverse from django.urls import reverse
from taggit.managers import TaggableManager
from dcim.models import Device from dcim.models import Device
from extras.models import TaggedItem
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import OrganizationalModel, PrimaryModel from netbox.models import OrganizationalModel, PrimaryModel
from ipam.choices import * from ipam.choices import *
@ -107,7 +105,6 @@ class Aggregate(PrimaryModel):
max_length=200, max_length=200,
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
@ -292,7 +289,6 @@ class Prefix(PrimaryModel):
max_length=200, max_length=200,
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = PrefixQuerySet.as_manager() objects = PrefixQuerySet.as_manager()
@ -564,7 +560,6 @@ class IPAddress(PrimaryModel):
max_length=200, max_length=200,
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = IPAddressManager() objects = IPAddressManager()

View File

@ -3,9 +3,7 @@ from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from taggit.managers import TaggableManager
from extras.models import TaggedItem
from extras.utils import extras_features from extras.utils import extras_features
from ipam.choices import * from ipam.choices import *
from ipam.constants import * from ipam.constants import *
@ -66,7 +64,6 @@ class Service(PrimaryModel):
max_length=200, max_length=200,
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -2,10 +2,8 @@ from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from taggit.managers import TaggableManager
from dcim.models import Interface from dcim.models import Interface
from extras.models import TaggedItem
from extras.utils import extras_features from extras.utils import extras_features
from ipam.choices import * from ipam.choices import *
from ipam.constants import * from ipam.constants import *
@ -135,7 +133,6 @@ class VLAN(PrimaryModel):
max_length=200, max_length=200,
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -1,8 +1,6 @@
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from taggit.managers import TaggableManager
from extras.models import TaggedItem
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
@ -59,7 +57,6 @@ class VRF(PrimaryModel):
related_name='exporting_vrfs', related_name='exporting_vrfs',
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
@ -116,7 +113,6 @@ class RouteTarget(PrimaryModel):
blank=True, blank=True,
null=True null=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -5,6 +5,7 @@ from django.core.serializers.json import DjangoJSONEncoder
from django.core.validators import ValidationError from django.core.validators import ValidationError
from django.db import models from django.db import models
from mptt.models import MPTTModel, TreeForeignKey from mptt.models import MPTTModel, TreeForeignKey
from taggit.managers import TaggableManager
from extras.choices import ObjectChangeActionChoices from extras.choices import ObjectChangeActionChoices
from utilities.mptt import TreeManager from utilities.mptt import TreeManager
@ -148,8 +149,7 @@ class PrimaryModel(ChangeLoggingMixin, CustomFieldsMixin, BigIDModel):
""" """
Primary models represent real objects within the infrastructure being modeled. Primary models represent real objects within the infrastructure being modeled.
""" """
# TODO tags = TaggableManager(through='extras.TaggedItem')
# tags = TaggableManager(through=TaggedItem)
class Meta: class Meta:
abstract = True abstract = True

View File

@ -12,9 +12,7 @@ from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes
from taggit.managers import TaggableManager
from extras.models import TaggedItem
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import BigIDModel, OrganizationalModel, PrimaryModel from netbox.models import BigIDModel, OrganizationalModel, PrimaryModel
from utilities.querysets import RestrictedQuerySet from utilities.querysets import RestrictedQuerySet
@ -312,7 +310,6 @@ class Secret(PrimaryModel):
max_length=128, max_length=128,
editable=False editable=False
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -1,9 +1,7 @@
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from mptt.models import MPTTModel, TreeForeignKey from mptt.models import MPTTModel, TreeForeignKey
from taggit.managers import TaggableManager
from extras.models import TaggedItem
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.mptt import TreeManager from utilities.mptt import TreeManager
@ -89,7 +87,6 @@ class Tenant(PrimaryModel):
comments = models.TextField( comments = models.TextField(
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()

View File

@ -1,4 +1,5 @@
import django.core.serializers.json import django.core.serializers.json
import taggit.managers
from django.db import migrations, models from django.db import migrations, models
@ -59,4 +60,9 @@ class Migration(migrations.Migration):
name='custom_field_data', name='custom_field_data',
field=models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder), field=models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder),
), ),
migrations.AlterField(
model_name='vminterface',
name='tags',
field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'),
),
] ]

View File

@ -3,10 +3,9 @@ from django.contrib.contenttypes.fields import GenericRelation
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from taggit.managers import TaggableManager
from dcim.models import BaseInterface, Device from dcim.models import BaseInterface, Device
from extras.models import ConfigContextModel, TaggedItem from extras.models import ConfigContextModel
from extras.querysets import ConfigContextModelQuerySet from extras.querysets import ConfigContextModelQuerySet
from extras.utils import extras_features from extras.utils import extras_features
from netbox.models import OrganizationalModel, PrimaryModel from netbox.models import OrganizationalModel, PrimaryModel
@ -154,7 +153,6 @@ class Cluster(PrimaryModel):
comments = models.TextField( comments = models.TextField(
blank=True blank=True
) )
tags = TaggableManager(through=TaggedItem)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
@ -281,7 +279,6 @@ class VirtualMachine(PrimaryModel, ConfigContextModel):
object_id_field='assigned_object_id', object_id_field='assigned_object_id',
related_query_name='virtual_machine' related_query_name='virtual_machine'
) )
tags = TaggableManager(through=TaggedItem)
objects = ConfigContextModelQuerySet.as_manager() objects = ConfigContextModelQuerySet.as_manager()
@ -412,10 +409,6 @@ class VMInterface(PrimaryModel, BaseInterface):
object_id_field='assigned_object_id', object_id_field='assigned_object_id',
related_query_name='vminterface' related_query_name='vminterface'
) )
tags = TaggableManager(
through=TaggedItem,
related_name='vminterface'
)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()