From ae736ef407295f07f02a159c558f33b17d238adf Mon Sep 17 00:00:00 2001 From: Martin Hauser Date: Tue, 10 Feb 2026 17:49:41 +0100 Subject: [PATCH] fix(dcim): Render device height as rack units via floatformat Use `TemplatedAttr` for device height and render using Django's `floatformat` filter so 0.0 is displayed as `0U` (and whole-U values omit the decimal). Fixes #21267 --- netbox/dcim/ui/panels.py | 4 ++-- netbox/netbox/ui/attrs.py | 2 +- netbox/templates/dcim/devicetype/attrs/height.html | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 netbox/templates/dcim/devicetype/attrs/height.html diff --git a/netbox/dcim/ui/panels.py b/netbox/dcim/ui/panels.py index f97eb97a4..7a5fe3de1 100644 --- a/netbox/dcim/ui/panels.py +++ b/netbox/dcim/ui/panels.py @@ -126,7 +126,7 @@ class DeviceDeviceTypePanel(panels.ObjectAttributesPanel): manufacturer = attrs.RelatedObjectAttr('device_type.manufacturer', linkify=True) model = attrs.RelatedObjectAttr('device_type', linkify=True) - height = attrs.TextAttr('device_type.u_height', format_string='{}U') + height = attrs.TemplatedAttr('device_type.u_height', template_name='dcim/devicetype/attrs/height.html') front_image = attrs.ImageAttr('device_type.front_image') rear_image = attrs.ImageAttr('device_type.rear_image') @@ -143,7 +143,7 @@ class DeviceTypePanel(panels.ObjectAttributesPanel): part_number = attrs.TextAttr('part_number') default_platform = attrs.RelatedObjectAttr('default_platform', linkify=True) description = attrs.TextAttr('description') - height = attrs.TextAttr('u_height', format_string='{}U', label=_('Height')) + height = attrs.TemplatedAttr('u_height', template_name='dcim/devicetype/attrs/height.html') exclude_from_utilization = attrs.BooleanAttr('exclude_from_utilization') full_depth = attrs.BooleanAttr('is_full_depth') weight = attrs.NumericAttr('weight', unit_accessor='get_weight_unit_display') diff --git a/netbox/netbox/ui/attrs.py b/netbox/netbox/ui/attrs.py index bf55e3f3c..999e02f94 100644 --- a/netbox/netbox/ui/attrs.py +++ b/netbox/netbox/ui/attrs.py @@ -103,7 +103,7 @@ class TextAttr(ObjectAttribute): def get_value(self, obj): value = resolve_attr_path(obj, self.accessor) # Apply format string (if any) - if value and self.format_string: + if value is not None and value != '' and self.format_string: return self.format_string.format(value) return value diff --git a/netbox/templates/dcim/devicetype/attrs/height.html b/netbox/templates/dcim/devicetype/attrs/height.html new file mode 100644 index 000000000..064ff5c5a --- /dev/null +++ b/netbox/templates/dcim/devicetype/attrs/height.html @@ -0,0 +1 @@ +{{ value|floatformat }}U