12826 add slug

This commit is contained in:
Arthur Hanson 2024-06-26 10:39:06 -07:00
parent 323bd24597
commit d6815ff033
7 changed files with 32 additions and 14 deletions

View File

@ -365,6 +365,16 @@ class RackFilterSet(NetBoxModelFilterSet, TenancyFilterSet, ContactModelFilterSe
to_field_name='slug', to_field_name='slug',
label=_('Location (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( status = django_filters.MultipleChoiceFilter(
choices=RackStatusChoices, choices=RackStatusChoices,
null_value=None null_value=None

View File

@ -208,8 +208,8 @@ class RackTypeImportForm(NetBoxModelImportForm):
class Meta: class Meta:
model = RackType model = RackType
fields = ( fields = (
'name', 'type', 'name', 'slug', 'type', 'width', 'u_height', 'desc_units', 'outer_width',
'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'weight', 'outer_depth', 'outer_unit', 'mounting_depth', 'weight',
'max_weight', 'weight_unit', 'description', 'comments', 'tags', 'max_weight', 'weight_unit', 'description', 'comments', 'tags',
) )

View File

@ -206,7 +206,7 @@ class RackTypeForm(NetBoxModelForm):
comments = CommentField() comments = CommentField()
fieldsets = ( fieldsets = (
FieldSet('name', 'description', 'tags', name=_('Rack')), FieldSet('name', 'slug', 'description', 'tags', name=_('Rack')),
FieldSet( FieldSet(
'type', 'width', 'starting_unit', 'u_height', 'type', 'width', 'starting_unit', 'u_height',
InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')), InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')),
@ -218,9 +218,9 @@ class RackTypeForm(NetBoxModelForm):
class Meta: class Meta:
model = RackType model = RackType
fields = [ fields = [
'name', 'name', 'slug', 'type', 'width', 'u_height', 'starting_unit', 'desc_units',
'type', 'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'weight', 'max_weight',
'outer_unit', 'mounting_depth', 'weight', 'max_weight', 'weight_unit', 'description', 'comments', 'tags', 'weight_unit', 'description', 'comments', 'tags',
] ]

View File

@ -39,6 +39,7 @@ class Migration(migrations.Migration):
'name', blank=True, max_length=100, naturalize_function=utilities.ordering.naturalize '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)), ('type', models.CharField(blank=True, max_length=50)),
('width', models.PositiveSmallIntegerField(default=19)), ('width', models.PositiveSmallIntegerField(default=19)),
( (

View File

@ -51,6 +51,11 @@ class RackType(PrimaryModel, WeightMixin):
max_length=100, max_length=100,
blank=True blank=True
) )
slug = models.SlugField(
verbose_name=_('slug'),
max_length=100,
unique=True
)
type = models.CharField( type = models.CharField(
choices=RackTypeChoices, choices=RackTypeChoices,
max_length=50, max_length=50,

View File

@ -80,7 +80,8 @@ class RackTypeTestCase(TestCase):
def setUpTestData(cls): def setUpTestData(cls):
RackType.objects.create( RackType.objects.create(
name='Rack 1', name='RackType 1',
slug='rack-type-1',
width=11, width=11,
u_height=22, u_height=22,
starting_unit=3, starting_unit=3,

View File

@ -343,9 +343,9 @@ class RackTypeTestCase(ViewTestCases.PrimaryObjectViewTestCase):
def setUpTestData(cls): def setUpTestData(cls):
racks = ( racks = (
Rack(name='RackType 1'), RackType(name='RackType 1', slug='rack-type-1',),
Rack(name='RackType 2'), RackType(name='RackType 2', slug='rack-type-2',),
Rack(name='RackType 3'), RackType(name='RackType 3', slug='rack-type-3',),
) )
RackType.objects.bulk_create(racks) RackType.objects.bulk_create(racks)
@ -353,6 +353,7 @@ class RackTypeTestCase(ViewTestCases.PrimaryObjectViewTestCase):
cls.form_data = { cls.form_data = {
'name': 'RackType X', 'name': 'RackType X',
'slug': 'rack-type-x',
'type': RackTypeChoices.TYPE_CABINET, 'type': RackTypeChoices.TYPE_CABINET,
'width': RackWidthChoices.WIDTH_19IN, 'width': RackWidthChoices.WIDTH_19IN,
'u_height': 48, 'u_height': 48,
@ -369,10 +370,10 @@ class RackTypeTestCase(ViewTestCases.PrimaryObjectViewTestCase):
} }
cls.csv_data = ( cls.csv_data = (
"name,width,u_height,weight,max_weight,weight_unit", "name,slug,width,u_height,weight,max_weight,weight_unit",
"RackType 4,19,42,100,2000,kg", "RackType 4,rack-type-4,19,42,100,2000,kg",
"RackType 5,19,42,100,2000,kg", "RackType 5,rack-type-5,19,42,100,2000,kg",
"RackType 6,19,42,100,2000,kg", "RackType 6,rack-type-6,19,42,100,2000,kg",
) )
cls.csv_update_data = ( cls.csv_update_data = (