Просмотр исходного кода

Clean up redundant NestedGroupModel, OrganizationalModel fields

jeremystretch 3 лет назад
Родитель
Сommit
e2f5ee661a

+ 1 - 1
netbox/circuits/migrations/0001_squashed.py

@@ -65,7 +65,7 @@ class Migration(migrations.Migration):
                 ('description', models.CharField(blank=True, max_length=200)),
             ],
             options={
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.CreateModel(

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

@@ -23,25 +23,6 @@ class CircuitType(OrganizationalModel):
     Circuits can be organized by their functional role. For example, a user might wish to define CircuitTypes named
     "Long Haul," "Metro," or "Out-of-Band".
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True,
-    )
-
-    class Meta:
-        ordering = ['name']
-
-    def __str__(self):
-        return self.name
-
     def get_absolute_url(self):
         return reverse('circuits:circuittype', args=[self.pk])
 

+ 4 - 4
netbox/dcim/migrations/0001_squashed.py

@@ -195,7 +195,7 @@ class Migration(migrations.Migration):
                 ('description', models.CharField(blank=True, max_length=200)),
             ],
             options={
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.CreateModel(
@@ -352,7 +352,7 @@ class Migration(migrations.Migration):
                 ('description', models.CharField(blank=True, max_length=200)),
             ],
             options={
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.CreateModel(
@@ -369,7 +369,7 @@ class Migration(migrations.Migration):
                 ('description', models.CharField(blank=True, max_length=200)),
             ],
             options={
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.CreateModel(
@@ -538,7 +538,7 @@ class Migration(migrations.Migration):
                 ('description', models.CharField(blank=True, max_length=200)),
             ],
             options={
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.CreateModel(

+ 1 - 1
netbox/dcim/migrations/0147_inventoryitemrole.py

@@ -27,7 +27,7 @@ class Migration(migrations.Migration):
                 ('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
             ],
             options={
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.AddField(

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

@@ -1025,27 +1025,9 @@ class InventoryItemRole(OrganizationalModel):
     """
     Inventory items may optionally be assigned a functional role.
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
     color = ColorField(
         default=ColorChoices.COLOR_GREY
     )
-    description = models.CharField(
-        max_length=200,
-        blank=True,
-    )
-
-    class Meta:
-        ordering = ['name']
-
-    def __str__(self):
-        return self.name
 
     def get_absolute_url(self):
         return reverse('dcim:inventoryitemrole', args=[self.pk])

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

@@ -45,30 +45,11 @@ class Manufacturer(OrganizationalModel):
     """
     A Manufacturer represents a company which produces hardware devices; for example, Juniper or Dell.
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
-
     # Generic relations
     contacts = GenericRelation(
         to='tenancy.ContactAssignment'
     )
 
-    class Meta:
-        ordering = ['name']
-
-    def __str__(self):
-        return self.name
-
     def get_absolute_url(self):
         return reverse('dcim:manufacturer', args=[self.pk])
 
@@ -418,14 +399,6 @@ class DeviceRole(OrganizationalModel):
     color to be used when displaying rack elevations. The vm_role field determines whether the role is applicable to
     virtual machines as well.
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
     color = ColorField(
         default=ColorChoices.COLOR_GREY
     )
@@ -434,16 +407,6 @@ class DeviceRole(OrganizationalModel):
         verbose_name='VM Role',
         help_text='Virtual machines may be assigned to this role'
     )
-    description = models.CharField(
-        max_length=200,
-        blank=True,
-    )
-
-    class Meta:
-        ordering = ['name']
-
-    def __str__(self):
-        return self.name
 
     def get_absolute_url(self):
         return reverse('dcim:devicerole', args=[self.pk])
@@ -455,14 +418,6 @@ class Platform(OrganizationalModel):
     NetBox uses Platforms to determine how to interact with devices when pulling inventory data or other information by
     specifying a NAPALM driver.
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
     manufacturer = models.ForeignKey(
         to='dcim.Manufacturer',
         on_delete=models.PROTECT,
@@ -483,16 +438,6 @@ class Platform(OrganizationalModel):
         verbose_name='NAPALM arguments',
         help_text='Additional arguments to pass when initiating the NAPALM driver (JSON format)'
     )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
-
-    class Meta:
-        ordering = ['name']
-
-    def __str__(self):
-        return self.name
 
     def get_absolute_url(self):
         return reverse('dcim:platform', args=[self.pk])

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

@@ -38,27 +38,9 @@ class RackRole(OrganizationalModel):
     """
     Racks can be organized by functional role, similar to Devices.
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
     color = ColorField(
         default=ColorChoices.COLOR_GREY
     )
-    description = models.CharField(
-        max_length=200,
-        blank=True,
-    )
-
-    class Meta:
-        ordering = ['name']
-
-    def __str__(self):
-        return self.name
 
     def get_absolute_url(self):
         return reverse('dcim:rackrole', args=[self.pk])

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

@@ -2,7 +2,6 @@ from django.contrib.contenttypes.fields import GenericRelation
 from django.core.exceptions import ValidationError
 from django.db import models
 from django.urls import reverse
-from mptt.models import TreeForeignKey
 from timezone_field import TimeZoneField
 
 from dcim.choices import *
@@ -28,25 +27,6 @@ class Region(NestedGroupModel):
     states, and/or cities. Regions are recursively nested into a hierarchy: all sites belonging to a child region are
     also considered to be members of its parent and ancestor region(s).
     """
-    parent = TreeForeignKey(
-        to='self',
-        on_delete=models.CASCADE,
-        related_name='children',
-        blank=True,
-        null=True,
-        db_index=True
-    )
-    name = models.CharField(
-        max_length=100
-    )
-    slug = models.SlugField(
-        max_length=100
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
-
     # Generic relations
     vlan_groups = GenericRelation(
         to='ipam.VLANGroup',
@@ -102,25 +82,6 @@ class SiteGroup(NestedGroupModel):
     within corporate sites you might distinguish between offices and data centers. Like regions, site groups can be
     nested recursively to form a hierarchy.
     """
-    parent = TreeForeignKey(
-        to='self',
-        on_delete=models.CASCADE,
-        related_name='children',
-        blank=True,
-        null=True,
-        db_index=True
-    )
-    name = models.CharField(
-        max_length=100
-    )
-    slug = models.SlugField(
-        max_length=100
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
-
     # Generic relations
     vlan_groups = GenericRelation(
         to='ipam.VLANGroup',
@@ -298,25 +259,11 @@ class Location(NestedGroupModel):
     A Location represents a subgroup of Racks and/or Devices within a Site. A Location may represent a building within a
     site, or a room within a building, for example.
     """
-    name = models.CharField(
-        max_length=100
-    )
-    slug = models.SlugField(
-        max_length=100
-    )
     site = models.ForeignKey(
         to='dcim.Site',
         on_delete=models.CASCADE,
         related_name='locations'
     )
-    parent = TreeForeignKey(
-        to='self',
-        on_delete=models.CASCADE,
-        related_name='children',
-        blank=True,
-        null=True,
-        db_index=True
-    )
     status = models.CharField(
         max_length=50,
         choices=LocationStatusChoices,
@@ -329,10 +276,6 @@ class Location(NestedGroupModel):
         blank=True,
         null=True
     )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
 
     # Generic relations
     vlan_groups = GenericRelation(

+ 2 - 2
netbox/ipam/migrations/0001_squashed.py

@@ -91,7 +91,7 @@ class Migration(migrations.Migration):
             options={
                 'verbose_name': 'RIR',
                 'verbose_name_plural': 'RIRs',
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.CreateModel(
@@ -107,7 +107,7 @@ class Migration(migrations.Migration):
                 ('description', models.CharField(blank=True, max_length=200)),
             ],
             options={
-                'ordering': ['weight', 'name'],
+                'ordering': ('weight', 'name'),
             },
         ),
         migrations.CreateModel(

+ 2 - 29
netbox/ipam/models/ip.py

@@ -61,32 +61,17 @@ class RIR(OrganizationalModel):
     A Regional Internet Registry (RIR) is responsible for the allocation of a large portion of the global IP address
     space. This can be an organization like ARIN or RIPE, or a governing standard such as RFC 1918.
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
     is_private = models.BooleanField(
         default=False,
         verbose_name='Private',
         help_text='IP space managed by this RIR is considered private'
     )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
 
     class Meta:
-        ordering = ['name']
+        ordering = ('name',)
         verbose_name = 'RIR'
         verbose_name_plural = 'RIRs'
 
-    def __str__(self):
-        return self.name
-
     def get_absolute_url(self):
         return reverse('ipam:rir', args=[self.pk])
 
@@ -265,24 +250,12 @@ class Role(OrganizationalModel):
     A Role represents the functional role of a Prefix or VLAN; for example, "Customer," "Infrastructure," or
     "Management."
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
     weight = models.PositiveSmallIntegerField(
         default=1000
     )
-    description = models.CharField(
-        max_length=200,
-        blank=True,
-    )
 
     class Meta:
-        ordering = ['weight', 'name']
+        ordering = ('weight', 'name')
 
     def __str__(self):
         return self.name

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

@@ -83,9 +83,6 @@ class VLANGroup(OrganizationalModel):
         verbose_name = 'VLAN group'
         verbose_name_plural = 'VLAN groups'
 
-    def __str__(self):
-        return self.name
-
     def get_absolute_url(self):
         return reverse('ipam:vlangroup', args=[self.pk])
 

+ 6 - 0
netbox/netbox/models/__init__.py

@@ -82,6 +82,9 @@ class NestedGroupModel(NetBoxFeatureSet, MPTTModel):
     name = models.CharField(
         max_length=100
     )
+    slug = models.SlugField(
+        max_length=100
+    )
     description = models.CharField(
         max_length=200,
         blank=True
@@ -135,3 +138,6 @@ class OrganizationalModel(NetBoxFeatureSet, models.Model):
     class Meta:
         abstract = True
         ordering = ('name',)
+
+    def __str__(self):
+        return self.name

+ 1 - 1
netbox/tenancy/migrations/0003_contacts.py

@@ -26,7 +26,7 @@ class Migration(migrations.Migration):
                 ('description', models.CharField(blank=True, max_length=200)),
             ],
             options={
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.CreateModel(

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

@@ -20,25 +20,6 @@ class ContactGroup(NestedGroupModel):
     """
     An arbitrary collection of Contacts.
     """
-    name = models.CharField(
-        max_length=100
-    )
-    slug = models.SlugField(
-        max_length=100
-    )
-    parent = TreeForeignKey(
-        to='self',
-        on_delete=models.CASCADE,
-        related_name='children',
-        blank=True,
-        null=True,
-        db_index=True
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
-
     class Meta:
         ordering = ['name']
         constraints = (
@@ -56,25 +37,6 @@ class ContactRole(OrganizationalModel):
     """
     Functional role for a Contact assigned to an object.
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True,
-    )
-
-    class Meta:
-        ordering = ['name']
-
-    def __str__(self):
-        return self.name
-
     def get_absolute_url(self):
         return reverse('tenancy:contactrole', args=[self.pk])
 

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

@@ -23,18 +23,6 @@ class TenantGroup(NestedGroupModel):
         max_length=100,
         unique=True
     )
-    parent = TreeForeignKey(
-        to='self',
-        on_delete=models.CASCADE,
-        related_name='children',
-        blank=True,
-        null=True,
-        db_index=True
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
 
     class Meta:
         ordering = ['name']

+ 2 - 2
netbox/virtualization/migrations/0001_squashed_0022.py

@@ -72,7 +72,7 @@ class Migration(migrations.Migration):
                 ('description', models.CharField(blank=True, max_length=200)),
             ],
             options={
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.CreateModel(
@@ -87,7 +87,7 @@ class Migration(migrations.Migration):
                 ('description', models.CharField(blank=True, max_length=200)),
             ],
             options={
-                'ordering': ['name'],
+                'ordering': ('name',),
             },
         ),
         migrations.CreateModel(

+ 0 - 38
netbox/virtualization/models.py

@@ -33,25 +33,6 @@ class ClusterType(OrganizationalModel):
     """
     A type of Cluster.
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
-
-    class Meta:
-        ordering = ['name']
-
-    def __str__(self):
-        return self.name
-
     def get_absolute_url(self):
         return reverse('virtualization:clustertype', args=[self.pk])
 
@@ -64,19 +45,6 @@ class ClusterGroup(OrganizationalModel):
     """
     An organizational group of Clusters.
     """
-    name = models.CharField(
-        max_length=100,
-        unique=True
-    )
-    slug = models.SlugField(
-        max_length=100,
-        unique=True
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
-
     # Generic relations
     vlan_groups = GenericRelation(
         to='ipam.VLANGroup',
@@ -88,12 +56,6 @@ class ClusterGroup(OrganizationalModel):
         to='tenancy.ContactAssignment'
     )
 
-    class Meta:
-        ordering = ['name']
-
-    def __str__(self):
-        return self.name
-
     def get_absolute_url(self):
         return reverse('virtualization:clustergroup', args=[self.pk])
 

+ 0 - 15
netbox/wireless/models.py

@@ -54,18 +54,6 @@ class WirelessLANGroup(NestedGroupModel):
         max_length=100,
         unique=True
     )
-    parent = TreeForeignKey(
-        to='self',
-        on_delete=models.CASCADE,
-        related_name='children',
-        blank=True,
-        null=True,
-        db_index=True
-    )
-    description = models.CharField(
-        max_length=200,
-        blank=True
-    )
 
     class Meta:
         ordering = ('name', 'pk')
@@ -77,9 +65,6 @@ class WirelessLANGroup(NestedGroupModel):
         )
         verbose_name = 'Wireless LAN Group'
 
-    def __str__(self):
-        return self.name
-
     def get_absolute_url(self):
         return reverse('wireless:wirelesslangroup', args=[self.pk])