From 1f288175e479bf475055c4cf3ccae9a69c67325a Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 10 Dec 2019 12:53:28 -0500 Subject: [PATCH] Add description field to RackRole and DeviceRole models (#3655) --- netbox/dcim/api/serializers.py | 6 +++-- netbox/dcim/forms.py | 4 ++-- .../dcim/migrations/0087_role_descriptions.py | 23 +++++++++++++++++++ netbox/dcim/models.py | 14 +++++++++-- netbox/dcim/tables.py | 15 ++++++------ 5 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 netbox/dcim/migrations/0087_role_descriptions.py diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index c6ca24905..defc6c8ca 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -108,7 +108,7 @@ class RackRoleSerializer(ValidatedModelSerializer): class Meta: model = RackRole - fields = ['id', 'name', 'slug', 'color', 'rack_count'] + fields = ['id', 'name', 'slug', 'color', 'description', 'rack_count'] class RackSerializer(TaggitSerializer, CustomFieldModelSerializer): @@ -301,7 +301,9 @@ class DeviceRoleSerializer(ValidatedModelSerializer): class Meta: model = DeviceRole - fields = ['id', 'name', 'slug', 'color', 'vm_role', 'device_count', 'virtualmachine_count'] + fields = [ + 'id', 'name', 'slug', 'color', 'vm_role', 'description', 'device_count', 'virtualmachine_count', + ] class PlatformSerializer(ValidatedModelSerializer): diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 831bb7c81..5f6a3e695 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -412,7 +412,7 @@ class RackRoleForm(BootstrapMixin, forms.ModelForm): class Meta: model = RackRole fields = [ - 'name', 'slug', 'color', + 'name', 'slug', 'color', 'description', ] @@ -1387,7 +1387,7 @@ class DeviceRoleForm(BootstrapMixin, forms.ModelForm): class Meta: model = DeviceRole fields = [ - 'name', 'slug', 'color', 'vm_role', + 'name', 'slug', 'color', 'vm_role', 'description', ] diff --git a/netbox/dcim/migrations/0087_role_descriptions.py b/netbox/dcim/migrations/0087_role_descriptions.py new file mode 100644 index 000000000..5f8fd9707 --- /dev/null +++ b/netbox/dcim/migrations/0087_role_descriptions.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.6 on 2019-12-10 17:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0086_device_name_nonunique'), + ] + + operations = [ + migrations.AddField( + model_name='devicerole', + name='description', + field=models.CharField(blank=True, max_length=100), + ), + migrations.AddField( + model_name='rackrole', + name='description', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 7e16bad95..d29a1e729 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -433,8 +433,12 @@ class RackRole(ChangeLoggedModel): unique=True ) color = ColorField() + description = models.CharField( + max_length=100, + blank=True, + ) - csv_headers = ['name', 'slug', 'color'] + csv_headers = ['name', 'slug', 'color', 'description'] class Meta: ordering = ['name'] @@ -450,6 +454,7 @@ class RackRole(ChangeLoggedModel): self.name, self.slug, self.color, + self.description, ) @@ -1412,8 +1417,12 @@ class DeviceRole(ChangeLoggedModel): verbose_name='VM Role', help_text='Virtual machines may be assigned to this role' ) + description = models.CharField( + max_length=100, + blank=True, + ) - csv_headers = ['name', 'slug', 'color', 'vm_role'] + csv_headers = ['name', 'slug', 'color', 'vm_role', 'description'] class Meta: ordering = ['name'] @@ -1427,6 +1436,7 @@ class DeviceRole(ChangeLoggedModel): self.slug, self.color, self.vm_role, + self.description, ) diff --git a/netbox/dcim/tables.py b/netbox/dcim/tables.py index 1b747ff75..7e1da41d4 100644 --- a/netbox/dcim/tables.py +++ b/netbox/dcim/tables.py @@ -272,16 +272,17 @@ class RackGroupTable(BaseTable): class RackRoleTable(BaseTable): pk = ToggleColumn() - name = tables.LinkColumn(verbose_name='Name') rack_count = tables.Column(verbose_name='Racks') - color = tables.TemplateColumn(COLOR_LABEL, verbose_name='Color') - slug = tables.Column(verbose_name='Slug') - actions = tables.TemplateColumn(template_code=RACKROLE_ACTIONS, attrs={'td': {'class': 'text-right noprint'}}, - verbose_name='') + color = tables.TemplateColumn(COLOR_LABEL) + actions = tables.TemplateColumn( + template_code=RACKROLE_ACTIONS, + attrs={'td': {'class': 'text-right noprint'}}, + verbose_name='' + ) class Meta(BaseTable.Meta): model = RackRole - fields = ('pk', 'name', 'rack_count', 'color', 'slug', 'actions') + fields = ('pk', 'name', 'rack_count', 'color', 'description', 'slug', 'actions') # @@ -614,7 +615,7 @@ class DeviceRoleTable(BaseTable): class Meta(BaseTable.Meta): model = DeviceRole - fields = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'slug', 'actions') + fields = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'slug', 'actions') #