mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Rack.status to slug (#3569)
This commit is contained in:
parent
62b45494b6
commit
8d27b62114
@ -117,7 +117,7 @@ class RackSerializer(TaggitSerializer, CustomFieldModelSerializer):
|
|||||||
tenant = NestedTenantSerializer(required=False, allow_null=True)
|
tenant = NestedTenantSerializer(required=False, allow_null=True)
|
||||||
status = ChoiceField(choices=RACK_STATUS_CHOICES, required=False)
|
status = ChoiceField(choices=RACK_STATUS_CHOICES, required=False)
|
||||||
role = NestedRackRoleSerializer(required=False, allow_null=True)
|
role = NestedRackRoleSerializer(required=False, allow_null=True)
|
||||||
type = ChoiceField(choices=RACK_TYPE_CHOICES, required=False, allow_null=True)
|
type = ChoiceField(choices=RackTypeChoices, required=False, allow_null=True)
|
||||||
width = ChoiceField(choices=RACK_WIDTH_CHOICES, required=False)
|
width = ChoiceField(choices=RACK_WIDTH_CHOICES, required=False)
|
||||||
outer_unit = ChoiceField(choices=RACK_DIMENSION_UNIT_CHOICES, required=False)
|
outer_unit = ChoiceField(choices=RACK_DIMENSION_UNIT_CHOICES, required=False)
|
||||||
tags = TagListSerializerField(required=False)
|
tags = TagListSerializerField(required=False)
|
||||||
|
@ -1,5 +1,33 @@
|
|||||||
from utilities.choices import ChoiceSet
|
from utilities.choices import ChoiceSet
|
||||||
from .constants import *
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Racks
|
||||||
|
#
|
||||||
|
|
||||||
|
class RackTypeChoices(ChoiceSet):
|
||||||
|
|
||||||
|
TYPE_2POST = '2-post-frame'
|
||||||
|
TYPE_4POST = '4-post-frame'
|
||||||
|
TYPE_CABINET = '4-post-cabinet'
|
||||||
|
TYPE_WALLFRAME = 'wall-frame'
|
||||||
|
TYPE_WALLCABINET = 'wall-cabinet'
|
||||||
|
|
||||||
|
CHOICES = (
|
||||||
|
(TYPE_2POST, '2-post frame'),
|
||||||
|
(TYPE_4POST, '4-post frame'),
|
||||||
|
(TYPE_CABINET, '4-post cabinet'),
|
||||||
|
(TYPE_WALLFRAME, 'Wall-mounted frame'),
|
||||||
|
(TYPE_WALLCABINET, 'Wall-mounted cabinet'),
|
||||||
|
)
|
||||||
|
|
||||||
|
LEGACY_MAP = {
|
||||||
|
TYPE_2POST: 100,
|
||||||
|
TYPE_4POST: 200,
|
||||||
|
TYPE_CABINET: 300,
|
||||||
|
TYPE_WALLFRAME: 1000,
|
||||||
|
TYPE_WALLCABINET: 1100,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -1,17 +1,3 @@
|
|||||||
# Rack types
|
|
||||||
RACK_TYPE_2POST = 100
|
|
||||||
RACK_TYPE_4POST = 200
|
|
||||||
RACK_TYPE_CABINET = 300
|
|
||||||
RACK_TYPE_WALLFRAME = 1000
|
|
||||||
RACK_TYPE_WALLCABINET = 1100
|
|
||||||
RACK_TYPE_CHOICES = (
|
|
||||||
(RACK_TYPE_2POST, '2-post frame'),
|
|
||||||
(RACK_TYPE_4POST, '4-post frame'),
|
|
||||||
(RACK_TYPE_CABINET, '4-post cabinet'),
|
|
||||||
(RACK_TYPE_WALLFRAME, 'Wall-mounted frame'),
|
|
||||||
(RACK_TYPE_WALLCABINET, 'Wall-mounted cabinet'),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Rack widths
|
# Rack widths
|
||||||
RACK_WIDTH_19IN = 19
|
RACK_WIDTH_19IN = 19
|
||||||
RACK_WIDTH_23IN = 23
|
RACK_WIDTH_23IN = 23
|
||||||
|
@ -487,7 +487,7 @@ class RackCSVForm(forms.ModelForm):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
type = CSVChoiceField(
|
type = CSVChoiceField(
|
||||||
choices=RACK_TYPE_CHOICES,
|
choices=RackTypeChoices,
|
||||||
required=False,
|
required=False,
|
||||||
help_text='Rack type'
|
help_text='Rack type'
|
||||||
)
|
)
|
||||||
@ -593,7 +593,7 @@ class RackBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditFor
|
|||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
type = forms.ChoiceField(
|
type = forms.ChoiceField(
|
||||||
choices=add_blank_choice(RACK_TYPE_CHOICES),
|
choices=add_blank_choice(RackTypeChoices),
|
||||||
required=False,
|
required=False,
|
||||||
widget=StaticSelect2()
|
widget=StaticSelect2()
|
||||||
)
|
)
|
||||||
|
33
netbox/dcim/migrations/0078_rack_choicefields_to_slugs.py
Normal file
33
netbox/dcim/migrations/0078_rack_choicefields_to_slugs.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
RACK_TYPE_CHOICES = (
|
||||||
|
(100, '2-post-frame'),
|
||||||
|
(200, '4-post-frame'),
|
||||||
|
(300, '4-post-cabinet'),
|
||||||
|
(1000, 'wall-frame'),
|
||||||
|
(1100, 'wall-cabinet'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def rack_type_to_slug(apps, schema_editor):
|
||||||
|
Rack = apps.get_model('dcim', 'Rack')
|
||||||
|
for id, slug in RACK_TYPE_CHOICES:
|
||||||
|
Rack.objects.filter(status=str(id)).update(status=slug)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('dcim', '0077_power_types'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='rack',
|
||||||
|
name='type',
|
||||||
|
field=models.CharField(blank=True, max_length=50),
|
||||||
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=rack_type_to_slug
|
||||||
|
)
|
||||||
|
]
|
@ -497,10 +497,10 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
|||||||
verbose_name='Asset tag',
|
verbose_name='Asset tag',
|
||||||
help_text='A unique tag used to identify this rack'
|
help_text='A unique tag used to identify this rack'
|
||||||
)
|
)
|
||||||
type = models.PositiveSmallIntegerField(
|
type = models.CharField(
|
||||||
choices=RACK_TYPE_CHOICES,
|
choices=RackTypeChoices,
|
||||||
|
max_length=50,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
|
||||||
verbose_name='Type'
|
verbose_name='Type'
|
||||||
)
|
)
|
||||||
width = models.PositiveSmallIntegerField(
|
width = models.PositiveSmallIntegerField(
|
||||||
|
Loading…
Reference in New Issue
Block a user