|
@@ -3027,24 +3027,18 @@ class Cable(ChangeLoggedModel):
|
|
|
('termination_b_type', 'termination_b_id'),
|
|
('termination_b_type', 'termination_b_id'),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- def __str__(self):
|
|
|
|
|
- if self.label:
|
|
|
|
|
- return self.label
|
|
|
|
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
|
|
+ super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
- # Save a copy of the PK on the instance since it's nullified if .delete() is called
|
|
|
|
|
- if not hasattr(self, 'id_string'):
|
|
|
|
|
- self.id_string = '#{}'.format(self.pk)
|
|
|
|
|
|
|
+ # A copy of the PK to be used by __str__ in case the object is deleted
|
|
|
|
|
+ self._pk = self.pk
|
|
|
|
|
|
|
|
- return self.id_string
|
|
|
|
|
|
|
+ def __str__(self):
|
|
|
|
|
+ return self.label or '#{}'.format(self._pk)
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
|
def get_absolute_url(self):
|
|
|
return reverse('dcim:cable', args=[self.pk])
|
|
return reverse('dcim:cable', args=[self.pk])
|
|
|
|
|
|
|
|
- def delete(self, *args, **kwargs):
|
|
|
|
|
- # Trigger the __str__ method to save the pk into `self.id_string`
|
|
|
|
|
- str(self)
|
|
|
|
|
- super().delete(*args, **kwargs)
|
|
|
|
|
-
|
|
|
|
|
def clean(self):
|
|
def clean(self):
|
|
|
|
|
|
|
|
# Validate that termination A exists
|
|
# Validate that termination A exists
|