diff --git a/netbox/dcim/filtersets.py b/netbox/dcim/filtersets.py index 783d7ccab..750b2fe29 100644 --- a/netbox/dcim/filtersets.py +++ b/netbox/dcim/filtersets.py @@ -365,6 +365,16 @@ class RackFilterSet(NetBoxModelFilterSet, TenancyFilterSet, ContactModelFilterSe to_field_name='slug', label=_('Location (slug)'), ) + rack_type = django_filters.ModelMultipleChoiceFilter( + field_name='rack_type__slug', + queryset=RackType.objects.all(), + to_field_name='slug', + label=_('Rack type (slug)'), + ) + rack_type_id = django_filters.ModelMultipleChoiceFilter( + queryset=RackType.objects.all(), + label=_('Rack type (ID)'), + ) status = django_filters.MultipleChoiceFilter( choices=RackStatusChoices, null_value=None diff --git a/netbox/dcim/forms/bulk_import.py b/netbox/dcim/forms/bulk_import.py index 86d65a6be..204172a19 100644 --- a/netbox/dcim/forms/bulk_import.py +++ b/netbox/dcim/forms/bulk_import.py @@ -208,8 +208,8 @@ class RackTypeImportForm(NetBoxModelImportForm): class Meta: model = RackType fields = ( - 'name', 'type', - 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'weight', + 'name', 'slug', 'type', 'width', 'u_height', 'desc_units', 'outer_width', + 'outer_depth', 'outer_unit', 'mounting_depth', '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 1e41c5daa..75f385f1f 100644 --- a/netbox/dcim/forms/model_forms.py +++ b/netbox/dcim/forms/model_forms.py @@ -206,7 +206,7 @@ class RackTypeForm(NetBoxModelForm): comments = CommentField() fieldsets = ( - FieldSet('name', 'description', 'tags', name=_('Rack')), + FieldSet('name', 'slug', 'description', 'tags', name=_('Rack')), FieldSet( 'type', 'width', 'starting_unit', 'u_height', InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')), @@ -218,9 +218,9 @@ class RackTypeForm(NetBoxModelForm): class Meta: model = RackType fields = [ - 'name', - 'type', 'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', - 'outer_unit', 'mounting_depth', 'weight', 'max_weight', 'weight_unit', 'description', 'comments', 'tags', + 'name', 'slug', 'type', 'width', 'u_height', 'starting_unit', 'desc_units', + 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'weight', 'max_weight', + 'weight_unit', 'description', 'comments', 'tags', ] diff --git a/netbox/dcim/migrations/0188_racktype.py b/netbox/dcim/migrations/0188_racktype.py index d2563dc9b..d5a477e17 100644 --- a/netbox/dcim/migrations/0188_racktype.py +++ b/netbox/dcim/migrations/0188_racktype.py @@ -39,6 +39,7 @@ class Migration(migrations.Migration): 'name', blank=True, max_length=100, naturalize_function=utilities.ordering.naturalize ), ), + ('slug', models.SlugField(max_length=100, unique=True)), ('type', models.CharField(blank=True, max_length=50)), ('width', models.PositiveSmallIntegerField(default=19)), ( diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index 7b6ccaecb..43a345b15 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -51,6 +51,11 @@ class RackType(PrimaryModel, WeightMixin): max_length=100, blank=True ) + slug = models.SlugField( + verbose_name=_('slug'), + max_length=100, + unique=True + ) type = models.CharField( choices=RackTypeChoices, max_length=50, diff --git a/netbox/dcim/tests/test_models.py b/netbox/dcim/tests/test_models.py index 0886ed8ea..475cef2af 100644 --- a/netbox/dcim/tests/test_models.py +++ b/netbox/dcim/tests/test_models.py @@ -80,7 +80,8 @@ class RackTypeTestCase(TestCase): def setUpTestData(cls): RackType.objects.create( - name='Rack 1', + name='RackType 1', + slug='rack-type-1', width=11, u_height=22, starting_unit=3, diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index 556159096..b68c51450 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -343,9 +343,9 @@ class RackTypeTestCase(ViewTestCases.PrimaryObjectViewTestCase): def setUpTestData(cls): racks = ( - Rack(name='RackType 1'), - Rack(name='RackType 2'), - Rack(name='RackType 3'), + RackType(name='RackType 1', slug='rack-type-1',), + RackType(name='RackType 2', slug='rack-type-2',), + RackType(name='RackType 3', slug='rack-type-3',), ) RackType.objects.bulk_create(racks) @@ -353,6 +353,7 @@ class RackTypeTestCase(ViewTestCases.PrimaryObjectViewTestCase): cls.form_data = { 'name': 'RackType X', + 'slug': 'rack-type-x', 'type': RackTypeChoices.TYPE_CABINET, 'width': RackWidthChoices.WIDTH_19IN, 'u_height': 48, @@ -369,10 +370,10 @@ class RackTypeTestCase(ViewTestCases.PrimaryObjectViewTestCase): } cls.csv_data = ( - "name,width,u_height,weight,max_weight,weight_unit", - "RackType 4,19,42,100,2000,kg", - "RackType 5,19,42,100,2000,kg", - "RackType 6,19,42,100,2000,kg", + "name,slug,width,u_height,weight,max_weight,weight_unit", + "RackType 4,rack-type-4,19,42,100,2000,kg", + "RackType 5,rack-type-5,19,42,100,2000,kg", + "RackType 6,rack-type-6,19,42,100,2000,kg", ) cls.csv_update_data = (