From 1d2aef71b22f7cefd4db109001d4798a774e8237 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 5 Nov 2025 15:56:12 -0500 Subject: [PATCH] Hide custom fields panels if no custom fields exist on the model --- netbox/extras/ui/panels.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/netbox/extras/ui/panels.py b/netbox/extras/ui/panels.py index 4ab50ded7..4cad3c76c 100644 --- a/netbox/extras/ui/panels.py +++ b/netbox/extras/ui/panels.py @@ -1,4 +1,5 @@ from django.contrib.contenttypes.models import ContentType +from django.template.loader import render_to_string from django.utils.translation import gettext_lazy as _ from netbox.ui import actions, panels @@ -11,6 +12,9 @@ __all__ = ( class CustomFieldsPanel(panels.ObjectPanel): + """ + Render a panel showing the value of all custom fields defined on the object. + """ template_name = 'ui/panels/custom_fields.html' title = _('Custom Fields') @@ -21,8 +25,18 @@ class CustomFieldsPanel(panels.ObjectPanel): 'custom_fields': obj.get_custom_fields_by_group(), } + def render(self, context): + ctx = self.get_context(context) + # Hide the panel if no custom fields exist + if not ctx['custom_fields']: + return '' + return render_to_string(self.template_name, self.get_context(context)) + class ImageAttachmentsPanel(panels.ObjectsTablePanel): + """ + Render a table listing all images attached to the object. + """ actions = [ actions.AddObject( 'extras.imageattachment', @@ -40,6 +54,9 @@ class ImageAttachmentsPanel(panels.ObjectsTablePanel): class TagsPanel(panels.ObjectPanel): + """ + Render a panel showing the tags assigned to the object. + """ template_name = 'ui/panels/tags.html' title = _('Tags')