diff --git a/netbox/dcim/api/serializers_/racks.py b/netbox/dcim/api/serializers_/racks.py index 17c1c174e..4a0fe5daa 100644 --- a/netbox/dcim/api/serializers_/racks.py +++ b/netbox/dcim/api/serializers_/racks.py @@ -73,12 +73,12 @@ class RackTypeSerializer(RackBaseSerializer): class Meta: model = RackType fields = [ - 'id', 'url', 'display_url', 'display', 'manufacturer', 'name', 'slug', 'description', 'form_factor', + 'id', 'url', 'display_url', 'display', 'manufacturer', 'model', 'slug', 'description', 'form_factor', 'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'weight', 'max_weight', 'weight_unit', 'mounting_depth', 'airflow', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', ] - brief_fields = ('id', 'url', 'display', 'manufacturer', 'name', 'slug', 'description') + brief_fields = ('id', 'url', 'display', 'manufacturer', 'model', 'slug', 'description') class RackSerializer(RackBaseSerializer): diff --git a/netbox/dcim/filtersets.py b/netbox/dcim/filtersets.py index 5e404179a..5359e5c7d 100644 --- a/netbox/dcim/filtersets.py +++ b/netbox/dcim/filtersets.py @@ -311,7 +311,7 @@ class RackTypeFilterSet(NetBoxModelFilterSet): class Meta: model = RackType fields = ( - 'id', 'name', 'slug', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', + 'id', 'model', 'slug', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'airflow', 'weight', 'max_weight', 'weight_unit', 'description', ) diff --git a/netbox/dcim/forms/bulk_import.py b/netbox/dcim/forms/bulk_import.py index 785b4fb42..2e537d978 100644 --- a/netbox/dcim/forms/bulk_import.py +++ b/netbox/dcim/forms/bulk_import.py @@ -222,7 +222,7 @@ class RackTypeImportForm(NetBoxModelImportForm): class Meta: model = RackType fields = ( - 'manufacturer', 'name', 'slug', 'form_factor', 'width', 'u_height', 'starting_unit', 'desc_units', + 'manufacturer', 'model', 'slug', 'form_factor', 'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'airflow', 'weight', 'max_weight', 'weight_unit', 'description', 'comments', 'tags', ) diff --git a/netbox/dcim/forms/model_forms.py b/netbox/dcim/forms/model_forms.py index 30c1cf3b9..6088fe0ae 100644 --- a/netbox/dcim/forms/model_forms.py +++ b/netbox/dcim/forms/model_forms.py @@ -211,7 +211,7 @@ class RackTypeForm(NetBoxModelForm): slug = SlugField() fieldsets = ( - FieldSet('manufacturer', 'name', 'slug', 'description', 'form_factor', 'airflow', 'tags', name=_('Rack Type')), + FieldSet('manufacturer', 'model', 'slug', 'description', 'form_factor', 'airflow', 'tags', name=_('Rack Type')), FieldSet( 'width', 'u_height', InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')), @@ -224,7 +224,7 @@ class RackTypeForm(NetBoxModelForm): class Meta: model = RackType fields = [ - 'manufacturer', 'name', 'slug', 'form_factor', 'width', 'u_height', 'starting_unit', 'desc_units', + 'manufacturer', 'model', 'slug', 'form_factor', 'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'weight', 'max_weight', 'weight_unit', 'airflow', 'description', 'comments', 'tags', ] diff --git a/netbox/dcim/migrations/0188_racktype.py b/netbox/dcim/migrations/0188_racktype.py index 18e4152b6..b23169093 100644 --- a/netbox/dcim/migrations/0188_racktype.py +++ b/netbox/dcim/migrations/0188_racktype.py @@ -37,14 +37,7 @@ class Migration(migrations.Migration): related_name='rack_types', to='dcim.manufacturer' )), - ('name', models.CharField(max_length=100)), - ('_name', utilities.fields.NaturalOrderingField( - 'name', - blank=True, - max_length=100, - naturalize_function=utilities.ordering.naturalize - ), - ), + ('model', models.CharField(max_length=100)), ('slug', models.SlugField(max_length=100, unique=True)), ('form_factor', models.CharField(blank=True, max_length=50)), ('width', models.PositiveSmallIntegerField(default=19)), @@ -71,7 +64,7 @@ class Migration(migrations.Migration): options={ 'verbose_name': 'racktype', 'verbose_name_plural': 'racktypes', - 'ordering': ('_name', 'pk'), + 'ordering': ('manufacturer', 'model'), }, ), migrations.RenameField( @@ -90,4 +83,16 @@ class Migration(migrations.Migration): to='dcim.racktype', ), ), + migrations.AddConstraint( + model_name='racktype', + constraint=models.UniqueConstraint( + fields=('manufacturer', 'model'), name='dcim_racktype_unique_manufacturer_model' + ), + ), + migrations.AddConstraint( + model_name='racktype', + constraint=models.UniqueConstraint( + fields=('manufacturer', 'slug'), name='dcim_racktype_unique_manufacturer_slug' + ), + ), ] diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index 8457271f4..68088b63a 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -136,15 +136,10 @@ class RackType(RackBase): on_delete=models.PROTECT, related_name='rack_types' ) - name = models.CharField( - verbose_name=_('name'), + model = models.CharField( + verbose_name=_('model'), max_length=100 ) - _name = NaturalOrderingField( - target_field='name', - max_length=100, - blank=True - ) slug = models.SlugField( verbose_name=_('slug'), max_length=100, @@ -160,19 +155,29 @@ class RackType(RackBase): ) class Meta: - ordering = ('_name', 'pk') # (site, location, name) may be non-unique + ordering = ('manufacturer', 'model') + constraints = ( + models.UniqueConstraint( + fields=('manufacturer', 'model'), + name='%(app_label)s_%(class)s_unique_manufacturer_model' + ), + models.UniqueConstraint( + fields=('manufacturer', 'slug'), + name='%(app_label)s_%(class)s_unique_manufacturer_slug' + ), + ) verbose_name = _('rack type') verbose_name_plural = _('rack types') def __str__(self): - return self.name + return self.model def get_absolute_url(self): return reverse('dcim:racktype', args=[self.pk]) @property def full_name(self): - return f"{self.manufacturer} {self.name}" + return f"{self.manufacturer} {self.model}" def clean(self): super().clean() diff --git a/netbox/dcim/tables/racks.py b/netbox/dcim/tables/racks.py index b8295c286..a6b704161 100644 --- a/netbox/dcim/tables/racks.py +++ b/netbox/dcim/tables/racks.py @@ -50,9 +50,8 @@ class RackRoleTable(NetBoxTable): # class RackTypeTable(NetBoxTable): - name = tables.Column( - verbose_name=_('Name'), - order_by=('_name',), + model = tables.Column( + verbose_name=_('Model'), linkify=True ) manufacturer = tables.Column( @@ -96,12 +95,12 @@ class RackTypeTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = RackType fields = ( - 'pk', 'id', 'name', 'manufacturer', 'form_factor', 'u_height', 'starting_unit', 'width', 'outer_width', + 'pk', 'id', 'model', 'manufacturer', 'form_factor', 'u_height', 'starting_unit', 'width', 'outer_width', 'outer_depth', 'mounting_depth', 'airflow', 'weight', 'max_weight', 'description', 'comments', 'instance_count', 'tags', 'created', 'last_updated', ) default_columns = ( - 'pk', 'name', 'manufacturer', 'type', 'u_height', 'description', 'instance_count', + 'pk', 'model', 'manufacturer', 'type', 'u_height', 'description', 'instance_count', )