Commit 7d1687d5 by Bodor Máté

Create image destroy view

parent b50c79c7
...@@ -97,3 +97,8 @@ class Image(models.Model): ...@@ -97,3 +97,8 @@ class Image(models.Model):
description=description description=description
) )
return new_image return new_image
def delete(self):
interface = OpenstackImageManager(settings.CONNECTION)
if interface.delete(self.remote_id):
super().delete()
# from django.shortcuts import render # from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ViewSet
from rest_framework.response import Response from rest_framework.response import Response
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from image.models import Image from image.models import Image
from image.serializers import ImageSerializer from image.serializers import ImageSerializer
class ImageViewSet(ModelViewSet): class ImageViewSet(ViewSet):
serializer_class = ImageSerializer
queryset = Image.objects.all() def list(self, request):
# def list(self, request): images = Image.object.all()
# return HttpResponse("list") serializer = ImageSerializer(images, many=True)
return HttpResponse(serializer.data)
def create(self, request): def create(self, request):
serializer = ImageSerializer(data=request.data) serializer = ImageSerializer(data=request.data)
...@@ -26,14 +29,18 @@ class ImageViewSet(ModelViewSet): ...@@ -26,14 +29,18 @@ class ImageViewSet(ModelViewSet):
serializer = ImageSerializer(instance=new_image) serializer = ImageSerializer(instance=new_image)
return Response(serializer.data) return Response(serializer.data)
# def retrieve(self, request, pk=None): def retrieve(self, request, pk=None):
# return HttpResponse("retrive") return Response(status=status.HTTP_204_NO_CONTENT)
# def update(self, request, pk=None):
# return HttpResponse("update")
# def partial_update(self, request, pk=None): def update(self, request, pk=None):
# return HttpResponse("patch") return HttpResponse("update")
# def destroy(self, request, pk=None): def partial_update(self, request, pk=None):
# return HttpResponse("delete") return HttpResponse("patch")
def destroy(self, request, pk=None):
queryset = Image.objects.all()
image = get_object_or_404(queryset, pk=pk)
image.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
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