Check if the template VM serializer object has template attr

This commit is contained in:
PCoder 2019-04-09 07:40:06 +02:00
parent 9f58fdd456
commit 85b251d2e6

View file

@ -137,12 +137,15 @@ class VirtualMachineSerializer(serializers.Serializer):
return price return price
def get_configuration(self, obj): def get_configuration(self, obj):
if hasattr(obj, 'template'):
template_id = obj.template.template_id template_id = obj.template.template_id
template = OpenNebulaManager().get_template(template_id) template = OpenNebulaManager().get_template(template_id)
if template.name.startswith('public-'): if template.name.startswith('public-'):
return template.name.lstrip('public-') return template.name.lstrip('public-')
else: else:
return template.name return template.name
else:
return ""
def get_ipv4(self, obj): def get_ipv4(self, obj):
""" """