uncloud-mravi/uncloud/ungleich_service/serializers.py

18 lines
681 B
Python

from rest_framework import serializers
from .models import MatrixServiceProduct
from uncloud_vm.serializers import VMProductSerializer
from uncloud_vm.models import VMProduct
class MatrixServiceProductSerializer(serializers.ModelSerializer):
vm = VMProductSerializer()
class Meta:
model = MatrixServiceProduct
fields = ['uuid', 'order', 'owner', 'status', 'vm', 'domain']
read_only_fields = ['uuid', 'order', 'owner', 'status']
def create(self, validated_data):
# Create VM
vm_data = validated_data.pop('vm')
vm = VMProduct.objects.create(**vm_data)
return MatrixServiceProduct.create(vm=vm, **validated_data)