mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Create id_string on Cable to preserve access to pk after object deletion
This commit is contained in:
@ -2414,7 +2414,7 @@ class Cable(ChangeLoggedModel):
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.label if self.label else '#{}'.format(self.pk)
|
||||
return self.label or self.id_string
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('dcim:cable', args=[self.pk])
|
||||
@ -2427,6 +2427,15 @@ class Cable(ChangeLoggedModel):
|
||||
|
||||
super(Cable, self).save(*args, **kwargs)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
super(Cable, self).__init__(*args, **kwargs)
|
||||
|
||||
# Create an ID string for use by __str__(). We have to save a copy of pk since it's nullified after .delete()
|
||||
# is called.
|
||||
self.id_string = '#{}'.format(self.pk)
|
||||
|
||||
|
||||
def get_path_endpoints(self):
|
||||
"""
|
||||
Traverse both ends of a cable path and return its connected endpoints. Note that one or both endpoints may be
|
||||
|
Reference in New Issue
Block a user