diff --git a/netbox_rack_concept/models.py b/netbox_rack_concept/models.py index 364764c..ebb5fe8 100644 --- a/netbox_rack_concept/models.py +++ b/netbox_rack_concept/models.py @@ -542,6 +542,14 @@ class ConceptComponent(NetBoxModel): def is_connected(self): return self.cable is not None + @property + def peer(self): + """The component on the other end of this component's cable, if any.""" + cable = self.cable + if cable is None: + return None + return cable.termination_b if cable.termination_a_id == self.pk else cable.termination_a + def get_paired_components(self): """ For a front or rear port, the port(s) on the other side it passes through to - diff --git a/netbox_rack_concept/tables.py b/netbox_rack_concept/tables.py index 788211a..ea8cfca 100644 --- a/netbox_rack_concept/tables.py +++ b/netbox_rack_concept/tables.py @@ -115,8 +115,21 @@ class ConceptComponentTable(NetBoxTable): concept = tables.Column(accessor='device__concept', linkify=True, verbose_name=_('Concept')) component_type = columns.ChoiceFieldColumn() color = columns.ColorColumn() - connection = tables.Column( - accessor='cable', linkify=True, orderable=False, verbose_name=_('Connection'), empty_values=() + connection = tables.TemplateColumn( + template_code=""" + {% with peer=record.peer %} + {% if peer %} + {{ peer.device }} + + {{ peer }} + {% else %} + {{ ''|placeholder }} + {% endif %} + {% endwith %} + """, + verbose_name=_('Connection'), + orderable=False, + empty_values=() ) connect = tables.TemplateColumn( template_code=""" @@ -139,9 +152,6 @@ class ConceptComponentTable(NetBoxTable): ) default_columns = ('name', 'device', 'component_type', 'port_type', 'connection', 'connect') - def render_connection(self, value, record): - return value if value else _('Not connected') - class ConceptCableTable(NetBoxTable): id = tables.Column(linkify=True, verbose_name=_('ID')) diff --git a/netbox_rack_concept/templates/netbox_rack_concept/conceptcomponent.html b/netbox_rack_concept/templates/netbox_rack_concept/conceptcomponent.html index 2f6ee3a..ae9b045 100644 --- a/netbox_rack_concept/templates/netbox_rack_concept/conceptcomponent.html +++ b/netbox_rack_concept/templates/netbox_rack_concept/conceptcomponent.html @@ -91,13 +91,7 @@