Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
portal
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
11
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7d1687d5
authored
Jul 22, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create image destroy view
parent
b50c79c7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
14 deletions
+26
-14
recircle/image/models.py
+5
-0
recircle/image/views.py
+21
-14
No files found.
recircle/image/models.py
View file @
7d1687d5
...
@@ -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
()
recircle/image/views.py
View file @
7d1687d5
# from django.shortcuts import render
# from django.shortcuts import render
from
rest_framework.viewsets
import
Model
ViewSet
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment