diff --git a/docs/release-notes/version-2.8.md b/docs/release-notes/version-2.8.md index 034568539..ae7005b4e 100644 --- a/docs/release-notes/version-2.8.md +++ b/docs/release-notes/version-2.8.md @@ -11,6 +11,7 @@ * [#4766](https://github.com/netbox-community/netbox/issues/4766) - Fix redirect after login when `next` is not specified * [#4772](https://github.com/netbox-community/netbox/issues/4772) - Fix "brief" format for the secrets REST API endpoint +* [#4774](https://github.com/netbox-community/netbox/issues/4774) - Fix exception when deleting a device with device bays * [#4775](https://github.com/netbox-community/netbox/issues/4775) - Allow selecting an alternate device type when creating component templates --- diff --git a/netbox/dcim/models/device_components.py b/netbox/dcim/models/device_components.py index 4005d41a4..1c02aa727 100644 --- a/netbox/dcim/models/device_components.py +++ b/netbox/dcim/models/device_components.py @@ -44,6 +44,9 @@ class ComponentModel(models.Model): class Meta: abstract = True + def __str__(self): + return getattr(self, 'name') + def to_objectchange(self, action): # Annotate the parent Device/VM try: @@ -261,9 +264,6 @@ class ConsolePort(CableTermination, ComponentModel): ordering = ('device', '_name') unique_together = ('device', 'name') - def __str__(self): - return self.name - def get_absolute_url(self): return self.device.get_absolute_url() @@ -316,9 +316,6 @@ class ConsoleServerPort(CableTermination, ComponentModel): ordering = ('device', '_name') unique_together = ('device', 'name') - def __str__(self): - return self.name - def get_absolute_url(self): return self.device.get_absolute_url() @@ -397,9 +394,6 @@ class PowerPort(CableTermination, ComponentModel): ordering = ('device', '_name') unique_together = ('device', 'name') - def __str__(self): - return self.name - def get_absolute_url(self): return self.device.get_absolute_url() @@ -547,9 +541,6 @@ class PowerOutlet(CableTermination, ComponentModel): ordering = ('device', '_name') unique_together = ('device', 'name') - def __str__(self): - return self.name - def get_absolute_url(self): return self.device.get_absolute_url() @@ -685,9 +676,6 @@ class Interface(CableTermination, ComponentModel): ordering = ('device', CollateAsChar('_name')) unique_together = ('device', 'name') - def __str__(self): - return self.name - def get_absolute_url(self): return reverse('dcim:interface', kwargs={'pk': self.pk}) @@ -893,9 +881,6 @@ class FrontPort(CableTermination, ComponentModel): ('rear_port', 'rear_port_position'), ) - def __str__(self): - return self.name - def to_csv(self): return ( self.device.identifier, @@ -958,9 +943,6 @@ class RearPort(CableTermination, ComponentModel): ordering = ('device', '_name') unique_together = ('device', 'name') - def __str__(self): - return self.name - def to_csv(self): return ( self.device.identifier, @@ -1009,9 +991,6 @@ class DeviceBay(ComponentModel): ordering = ('device', '_name') unique_together = ('device', 'name') - def __str__(self): - return '{} - {}'.format(self.device.name, self.name) - def get_absolute_url(self): return self.device.get_absolute_url()