mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-21 12:52:21 -06:00
Add a description field to all organizational models
This commit is contained in:
@@ -17,7 +17,7 @@ class TenantGroupSerializer(ValidatedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = TenantGroup
|
||||
fields = ['id', 'name', 'slug', 'parent', 'tenant_count']
|
||||
fields = ['id', 'name', 'slug', 'parent', 'description', 'tenant_count']
|
||||
|
||||
|
||||
class TenantSerializer(TaggitSerializer, CustomFieldModelSerializer):
|
||||
|
||||
@@ -27,7 +27,7 @@ class TenantGroupFilterSet(BaseFilterSet, NameSlugSearchFilterSet):
|
||||
|
||||
class Meta:
|
||||
model = TenantGroup
|
||||
fields = ['id', 'name', 'slug']
|
||||
fields = ['id', 'name', 'slug', 'description']
|
||||
|
||||
|
||||
class TenantFilterSet(BaseFilterSet, CustomFieldFilterSet, CreatedUpdatedFilterSet):
|
||||
|
||||
@@ -28,7 +28,7 @@ class TenantGroupForm(BootstrapMixin, forms.ModelForm):
|
||||
class Meta:
|
||||
model = TenantGroup
|
||||
fields = [
|
||||
'parent', 'name', 'slug',
|
||||
'parent', 'name', 'slug', 'description',
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -34,8 +34,12 @@ class TenantGroup(MPTTModel, ChangeLoggedModel):
|
||||
null=True,
|
||||
db_index=True
|
||||
)
|
||||
description = models.CharField(
|
||||
max_length=200,
|
||||
blank=True
|
||||
)
|
||||
|
||||
csv_headers = ['name', 'slug', 'parent']
|
||||
csv_headers = ['name', 'slug', 'parent', 'description']
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
@@ -54,6 +58,7 @@ class TenantGroup(MPTTModel, ChangeLoggedModel):
|
||||
self.name,
|
||||
self.slug,
|
||||
self.parent.name if self.parent else '',
|
||||
self.description,
|
||||
)
|
||||
|
||||
def to_objectchange(self, action):
|
||||
|
||||
@@ -53,7 +53,7 @@ class TenantGroupTable(BaseTable):
|
||||
|
||||
class Meta(BaseTable.Meta):
|
||||
model = TenantGroup
|
||||
fields = ('pk', 'name', 'tenant_count', 'slug', 'actions')
|
||||
fields = ('pk', 'name', 'tenant_count', 'description', 'slug', 'actions')
|
||||
|
||||
|
||||
#
|
||||
|
||||
@@ -20,9 +20,9 @@ class TenantGroupTestCase(TestCase):
|
||||
tenantgroup.save()
|
||||
|
||||
tenant_groups = (
|
||||
TenantGroup(name='Tenant Group 1', slug='tenant-group-1', parent=parent_tenant_groups[0]),
|
||||
TenantGroup(name='Tenant Group 2', slug='tenant-group-2', parent=parent_tenant_groups[1]),
|
||||
TenantGroup(name='Tenant Group 3', slug='tenant-group-3', parent=parent_tenant_groups[2]),
|
||||
TenantGroup(name='Tenant Group 1', slug='tenant-group-1', parent=parent_tenant_groups[0], description='A'),
|
||||
TenantGroup(name='Tenant Group 2', slug='tenant-group-2', parent=parent_tenant_groups[1], description='B'),
|
||||
TenantGroup(name='Tenant Group 3', slug='tenant-group-3', parent=parent_tenant_groups[2], description='C'),
|
||||
)
|
||||
for tenantgroup in tenant_groups:
|
||||
tenantgroup.save()
|
||||
@@ -40,6 +40,10 @@ class TenantGroupTestCase(TestCase):
|
||||
params = {'slug': ['tenant-group-1', 'tenant-group-2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['A', 'B']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_parent(self):
|
||||
parent_groups = TenantGroup.objects.filter(name__startswith='Parent')[:2]
|
||||
params = {'parent_id': [parent_groups[0].pk, parent_groups[1].pk]}
|
||||
|
||||
@@ -19,13 +19,14 @@ class TenantGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
||||
cls.form_data = {
|
||||
'name': 'Tenant Group X',
|
||||
'slug': 'tenant-group-x',
|
||||
'description': 'A new tenant group',
|
||||
}
|
||||
|
||||
cls.csv_data = (
|
||||
"name,slug",
|
||||
"Tenant Group 4,tenant-group-4",
|
||||
"Tenant Group 5,tenant-group-5",
|
||||
"Tenant Group 6,tenant-group-6",
|
||||
"name,slug,description",
|
||||
"Tenant Group 4,tenant-group-4,Fourth tenant group",
|
||||
"Tenant Group 5,tenant-group-5,Fifth tenant group",
|
||||
"Tenant Group 6,tenant-group-6,Sixth tenant group",
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user