Add label to DeviceBay models and serializers

This commit is contained in:
Jonathan Senecal 2020-06-11 10:19:53 -04:00
parent c1eea166c9
commit a37d06064a
4 changed files with 24 additions and 5 deletions

View File

@ -331,7 +331,7 @@ class DeviceBayTemplateSerializer(ValidatedModelSerializer):
class Meta:
model = DeviceBayTemplate
fields = ['id', 'device_type', 'name']
fields = ['id', 'device_type', 'name', 'label']
#
@ -603,7 +603,7 @@ class DeviceBaySerializer(TaggitSerializer, ValidatedModelSerializer):
class Meta:
model = DeviceBay
fields = ['id', 'device', 'name', 'description', 'installed_device', 'tags']
fields = ['id', 'device', 'name', 'label', 'description', 'installed_device', 'tags']
#

View File

@ -60,4 +60,14 @@ class Migration(migrations.Migration):
name='label',
field=models.CharField(blank=True, max_length=64),
),
migrations.AddField(
model_name='devicebay',
name='label',
field=models.CharField(blank=True, max_length=64),
),
migrations.AddField(
model_name='devicebaytemplate',
name='label',
field=models.CharField(blank=True, max_length=64),
),
]

View File

@ -433,14 +433,16 @@ class DeviceBayTemplate(ComponentTemplateModel):
max_length=100,
blank=True
)
label = models.CharField(
max_length=64,
blank=True,
help_text="Physical label"
)
class Meta:
ordering = ('device_type', '_name')
unique_together = ('device_type', 'name')
def __str__(self):
return self.name
def instantiate(self, device):
return DeviceBay(
device=device,

View File

@ -1009,6 +1009,11 @@ class DeviceBay(ComponentModel):
max_length=100,
blank=True
)
label = models.CharField(
max_length=64,
blank=True,
help_text="Physical label"
)
installed_device = models.OneToOneField(
to='dcim.Device',
on_delete=models.SET_NULL,
@ -1025,6 +1030,8 @@ class DeviceBay(ComponentModel):
unique_together = ('device', 'name')
def __str__(self):
if self.label:
return '{} - {} ({})'.format(self.device.name, self.name, self.label)
return '{} - {}'.format(self.device.name, self.name)
def get_absolute_url(self):