17058 RackType name -> model (#17059)

* 17058 RackType name -> model

* 17058 RackType name -> model

* 17058 fix tests

* 17058 fix tests
This commit is contained in:
Arthur Hanson
2024-08-01 20:06:51 +07:00
committed by GitHub
parent c51e91dddd
commit d6f2fc7d29
15 changed files with 74 additions and 59 deletions

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