From 1119209fa0bd06c1407e9d33dab4b9985034e373 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 1 Nov 2018 13:39:39 -0400 Subject: [PATCH] Added CSV export for cables --- netbox/dcim/models.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 9f56dd2f8..6e876c360 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -2407,6 +2407,11 @@ class Cable(ChangeLoggedModel): objects = CableQuerySet.as_manager() + csv_headers = [ + 'termination_a_type', 'termination_a_id', 'termination_b_type', 'termination_b_id', 'type', 'status', 'label', + 'color', 'length', 'length_unit', + ] + class Meta: unique_together = ( ('termination_a_type', 'termination_a_id'), @@ -2461,6 +2466,20 @@ class Cable(ChangeLoggedModel): super(Cable, self).save(*args, **kwargs) + def to_csv(self): + return ( + '{}.{}'.format(self.termination_a_type.app_label, self.termination_a_type.model), + self.termination_a_id, + '{}.{}'.format(self.termination_b_type.app_label, self.termination_b_type.model), + self.termination_b_id, + self.get_type_display(), + self.get_status_display(), + self.label, + self.color, + self.length, + self.length_unit, + ) + 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