17058 RackType name -> model

This commit is contained in:
Arthur Hanson 2024-08-01 14:21:05 +07:00
parent 1a6406632a
commit c2b325974a
7 changed files with 39 additions and 30 deletions

View File

@ -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):

View File

@ -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',
)

View File

@ -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',
)

View File

@ -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',
]

View File

@ -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'
),
),
]

View File

@ -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()

View File

@ -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',
)