Enabled export templates for services

This commit is contained in:
Jeremy Stretch
2018-07-12 16:59:22 -04:00
parent 67dbe02deb
commit 81b1d54859
3 changed files with 16 additions and 1 deletions

View File

@@ -880,6 +880,7 @@ class Service(ChangeLoggedModel, CustomFieldModel):
tags = TaggableManager()
serializer = 'ipam.api.serializers.ServiceSerializer'
csv_headers = ['device', 'virtual_machine', 'name', 'protocol', 'description']
class Meta:
ordering = ['protocol', 'port']
@@ -901,3 +902,13 @@ class Service(ChangeLoggedModel, CustomFieldModel):
raise ValidationError("A service cannot be associated with both a device and a virtual machine.")
if not self.device and not self.virtual_machine:
raise ValidationError("A service must be associated with either a device or a virtual machine.")
def to_csv(self):
return (
self.device.name if self.device else None,
self.virtual_machine.name if self.virtual_machine else None,
self.name,
self.get_protocol_display(),
self.port,
self.description,
)