Commit a63c5cd1 by Chif Gergő

Update serializer and create view

parent 878edb70
......@@ -11,17 +11,7 @@ class InstanceFromTemplateSerializer(serializers.Serializer):
class ImageTemplateModelSerializer(serializers.ModelSerializer):
class Meta:
model = ImageTemplate
fields = (
"id",
"name",
"description",
"created_at",
"created_by",
"image",
"flavor",
"lease",
"type",
)
fields = "__all__"
read_only_fields = (
"created_at",
"created_by",
......
......@@ -10,17 +10,21 @@ class ImageTemplateViewSet(ModelViewSet):
queryset = ImageTemplate.objects.all()
def create(self, request):
# TODO: Check the permissions to create template and using the flavors and leases
serializer = ImageTemplateModelSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
data = serializer.validated_data
new_template = ImageTemplate.create(
name=data["name"],
description=data["description"],
access_protocol=data["access"],
system_type=data["system"],
distro=data["distro"],
created_by=request.user,
image=data["image"],
lease=data["lease"],
flavor=data["flavor"],
type="U"
type="IMAGE"
)
serializer = ImageTemplateModelSerializer(instance=new_template)
return Response(serializer.data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment