Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions netbox_custom_objects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ def __str__(self):
self, primary_field["name"]
)
if not primary_field_value:
# self.pk is set to None by Django's Model.delete() after the DB row
# is gone; NetBox's delete-toast and changelog renderers call str()
# on the post-delete instance, so include the PK only when it still
# exists. Otherwise return just the type label rather than "<type>
# None" which was the previous output (observed in delete toasts
# like "Deleted SmokeTabTarget SmokeTabTarget None").
if self.pk is None:
return str(self.custom_object_type.display_name)
return f"{self.custom_object_type.display_name} {self.id}"
return str(primary_field_value) or str(self.id)

Expand Down