Commit a63c5cd1 by Chif Gergő

Update serializer and create view

parent 878edb70
...@@ -11,17 +11,7 @@ class InstanceFromTemplateSerializer(serializers.Serializer): ...@@ -11,17 +11,7 @@ class InstanceFromTemplateSerializer(serializers.Serializer):
class ImageTemplateModelSerializer(serializers.ModelSerializer): class ImageTemplateModelSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = ImageTemplate model = ImageTemplate
fields = ( fields = "__all__"
"id",
"name",
"description",
"created_at",
"created_by",
"image",
"flavor",
"lease",
"type",
)
read_only_fields = ( read_only_fields = (
"created_at", "created_at",
"created_by", "created_by",
......
...@@ -10,17 +10,21 @@ class ImageTemplateViewSet(ModelViewSet): ...@@ -10,17 +10,21 @@ class ImageTemplateViewSet(ModelViewSet):
queryset = ImageTemplate.objects.all() queryset = ImageTemplate.objects.all()
def create(self, request): def create(self, request):
# TODO: Check the permissions to create template and using the flavors and leases
serializer = ImageTemplateModelSerializer(data=request.data) serializer = ImageTemplateModelSerializer(data=request.data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
data = serializer.validated_data data = serializer.validated_data
new_template = ImageTemplate.create( new_template = ImageTemplate.create(
name=data["name"], name=data["name"],
description=data["description"], description=data["description"],
access_protocol=data["access"],
system_type=data["system"],
distro=data["distro"],
created_by=request.user, created_by=request.user,
image=data["image"], image=data["image"],
lease=data["lease"], lease=data["lease"],
flavor=data["flavor"], flavor=data["flavor"],
type="U" type="IMAGE"
) )
serializer = ImageTemplateModelSerializer(instance=new_template) serializer = ImageTemplateModelSerializer(instance=new_template)
return Response(serializer.data) 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