From 0c15d7a1a965d3595f02284808d664d7e01104b8 Mon Sep 17 00:00:00 2001 From: Martin Hauser Date: Wed, 4 Jun 2025 07:07:41 +0200 Subject: [PATCH 1/2] feat(tags): Add object types field to Tag import form Introduces the `object_types` field in the Tag bulk import form, allowing assignment of one or more object types to Tags. --- netbox/extras/forms/bulk_import.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/netbox/extras/forms/bulk_import.py b/netbox/extras/forms/bulk_import.py index 5c62932e50d..cf15495cacd 100644 --- a/netbox/extras/forms/bulk_import.py +++ b/netbox/extras/forms/bulk_import.py @@ -238,10 +238,18 @@ class TagImportForm(CSVModelForm): label=_('Weight'), required=False ) + object_types = CSVMultipleContentTypeField( + label=_('Object types'), + queryset=ObjectType.objects.with_feature('tags'), + help_text=_("One or more assigned object types"), + required=False, + ) class Meta: model = Tag - fields = ('name', 'slug', 'color', 'weight', 'description') + fields = ( + 'name', 'slug', 'color', 'weight', 'description', 'object_types', + ) class JournalEntryImportForm(NetBoxModelImportForm): From 2ed7cad02268cf67c335e544f095239c3d0f2073 Mon Sep 17 00:00:00 2001 From: Martin Hauser Date: Wed, 4 Jun 2025 15:53:34 +0200 Subject: [PATCH 2/2] feat(tags): Add support for object types in tag tests Enhances tag-related tests to include `object_types` in setup data. Updates CSV data to support object type assignments for improved test coverage and functionality. --- netbox/extras/tests/test_views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/netbox/extras/tests/test_views.py b/netbox/extras/tests/test_views.py index 6378b29b8f3..fd3ce54534a 100644 --- a/netbox/extras/tests/test_views.py +++ b/netbox/extras/tests/test_views.py @@ -444,6 +444,8 @@ class TagTestCase(ViewTestCases.OrganizationalObjectViewTestCase): @classmethod def setUpTestData(cls): + site_ct = ContentType.objects.get_for_model(Site) + tags = ( Tag(name='Tag 1', slug='tag-1'), Tag(name='Tag 2', slug='tag-2', weight=1), @@ -456,14 +458,15 @@ def setUpTestData(cls): 'slug': 'tag-x', 'color': 'c0c0c0', 'comments': 'Some comments', + 'object_types': [site_ct.pk], 'weight': 11, } cls.csv_data = ( - "name,slug,color,description,weight", - "Tag 4,tag-4,ff0000,Fourth tag,0", - "Tag 5,tag-5,00ff00,Fifth tag,1111", - "Tag 6,tag-6,0000ff,Sixth tag,0", + "name,slug,color,description,object_types,weight", + "Tag 4,tag-4,ff0000,Fourth tag,dcim.interface,0", + "Tag 5,tag-5,00ff00,Fifth tag,'dcim.device,dcim.site',1111", + "Tag 6,tag-6,0000ff,Sixth tag,dcim.site,0", ) cls.csv_update_data = (