From bba0ebf35590d3f418f053e19175a4c22762962a Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 9 Dec 2025 15:00:38 -0800 Subject: [PATCH 1/3] #284 add tags in custom objects table --- netbox_custom_objects/tables.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/netbox_custom_objects/tables.py b/netbox_custom_objects/tables.py index 58f1d6a..5827972 100644 --- a/netbox_custom_objects/tables.py +++ b/netbox_custom_objects/tables.py @@ -9,6 +9,7 @@ from netbox.tables import NetBoxTable, columns from utilities.permissions import get_permission_for_model +from netbox_custom_objects.constants import APP_LABEL from netbox_custom_objects.models import CustomObject, CustomObjectType from netbox_custom_objects.utilities import get_viewname @@ -56,7 +57,7 @@ class CustomObjectTypeTable(NetBoxTable): verbose_name=_('Comments'), ) tags = columns.TagColumn( - url_name='circuits:provider_list' + url_name='plugins:netbox_custom_objects:customobjecttype_list' ) name = tables.Column( verbose_name=_('Name'), @@ -87,6 +88,31 @@ class Meta(NetBoxTable.Meta): ) +class CustomObjectTagColumn(columns.TagColumn): + """ + Custom TagColumn that generates tag filter URLs with the custom_object_type slug. + """ + template_code = """ + {% load helpers %} + {% for tag in value.all %} + + {{ tag }} + + {% empty %} + + {% endfor %} + """ + + def __init__(self): + # Override parent __init__ to use our custom template + tables.TemplateColumn.__init__( + self, + orderable=False, + template_code=self.template_code, + verbose_name=_('Tags'), + ) + + class CustomObjectActionsColumn(columns.ActionsColumn): def render(self, record, table, **kwargs): @@ -178,6 +204,7 @@ class CustomObjectTable(NetBoxTable): actions = CustomObjectActionsColumn( actions=('edit', 'delete'), ) + tags = CustomObjectTagColumn() class Meta(NetBoxTable.Meta): model = CustomObject @@ -188,6 +215,7 @@ class Meta(NetBoxTable.Meta): "custom_object_type", "created", "last_updated", + "tags", ) default_columns = ( "pk", From 9367499e8728b350d79c4d8928d2fddd8d7d8a47 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 9 Dec 2025 15:10:37 -0800 Subject: [PATCH 2/3] #284 add tags filter to list view filters --- netbox_custom_objects/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/netbox_custom_objects/views.py b/netbox_custom_objects/views.py index e7e261a..74faa57 100644 --- a/netbox_custom_objects/views.py +++ b/netbox_custom_objects/views.py @@ -20,6 +20,7 @@ from netbox.views import generic from netbox.views.generic.mixins import TableMixin from utilities.forms import ConfirmationForm +from utilities.forms.fields import TagFilterField from utilities.htmx import htmx_partial from utilities.views import ConditionalLoginRequiredMixin, ViewTab, get_viewname, register_model_view @@ -345,6 +346,7 @@ def get_filterset_form(self): attrs = { "model": model, "__module__": "database.filterset_forms", + "tag": TagFilterField(model), } for field in self.custom_object_type.fields.all(): From aae4ad2def4599157dc2bc06ef92eea5af9ae659 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 9 Dec 2025 15:18:37 -0800 Subject: [PATCH 3/3] fix ruff errors --- netbox_custom_objects/tables.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/netbox_custom_objects/tables.py b/netbox_custom_objects/tables.py index 5827972..935c52d 100644 --- a/netbox_custom_objects/tables.py +++ b/netbox_custom_objects/tables.py @@ -9,7 +9,6 @@ from netbox.tables import NetBoxTable, columns from utilities.permissions import get_permission_for_model -from netbox_custom_objects.constants import APP_LABEL from netbox_custom_objects.models import CustomObject, CustomObjectType from netbox_custom_objects.utilities import get_viewname @@ -95,8 +94,13 @@ class CustomObjectTagColumn(columns.TagColumn): template_code = """ {% load helpers %} {% for tag in value.all %} - - {{ tag }} + + + {{ tag }} + {% empty %}