Просмотр исходного кода

Closes #5143: Include a device's asset tag in its display value

jeremystretch 4 лет назад
Родитель
Сommit
9a45547cda
2 измененных файлов с 6 добавлено и 1 удалено
  1. 3 0
      docs/release-notes/version-3.1.md
  2. 3 1
      netbox/dcim/models/devices.py

+ 3 - 0
docs/release-notes/version-3.1.md

@@ -7,6 +7,7 @@
 
 ### Enhancements
 
+* [#5143](https://github.com/netbox-community/netbox/issues/5143) - Include a device's asset tag in its display value
 * [#7619](https://github.com/netbox-community/netbox/issues/7619) - Permit custom validation rules to be defined as plain data or dotted path to class
 * [#7761](https://github.com/netbox-community/netbox/issues/7761) - Extend cable tracing across bridged interfaces
 * [#7769](https://github.com/netbox-community/netbox/issues/7769) - Enable assignment of IP addresses to an existing FHRP group
@@ -25,6 +26,8 @@
 
 ### REST API Changes
 
+* dcim.Device
+    * The `display` field now includes the device's asset tag, if set
 * extras.ImageAttachment
     * Added the `last_updated` field
 

+ 3 - 1
netbox/dcim/models/devices.py

@@ -604,7 +604,9 @@ class Device(PrimaryModel, ConfigContextModel):
         )
 
     def __str__(self):
-        if self.name:
+        if self.name and self.asset_tag:
+            return f'{self.name} ({self.asset_tag})'
+        elif self.name:
             return self.name
         elif self.virtual_chassis:
             return f'{self.virtual_chassis.name}:{self.vc_position} ({self.pk})'