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
70b0f82c
authored
Apr 17, 2019
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic REST functionality for Instance
Added GET and POST endpoints for Instance
parent
dfb3cb58
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
2 deletions
+38
-2
recircle/instance/serializers.py
+12
-0
recircle/instance/urls.py
+2
-1
recircle/instance/views.py
+24
-1
No files found.
recircle/instance/serializers.py
0 → 100644
View file @
70b0f82c
from
rest_framework
import
serializers
from
.models
import
Instance
class
InstanceSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Instance
fields
=
(
"name"
,
"description"
,
)
recircle/instance/urls.py
View file @
70b0f82c
...
...
@@ -3,5 +3,5 @@ from django.urls import path
from
.
import
views
urlpatterns
=
[
path
(
''
,
views
.
in
dex
,
name
=
'index'
),
path
(
''
,
views
.
in
stance_list
),
]
\ No newline at end of file
recircle/instance/views.py
View file @
70b0f82c
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
,
JsonResponse
from
django.views.decorators.csrf
import
csrf_exempt
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework.parsers
import
JSONParser
from
instance.models
import
Instance
from
instance.serializers
import
InstanceSerializer
def
index
(
request
):
return
HttpResponse
(
"Hello, world. You're at the instance index."
)
@csrf_exempt
def
instance_list
(
request
):
"""
List all instances, or create a new one.
"""
if
request
.
method
==
'GET'
:
instances
=
Instance
.
objects
.
all
()
serializer
=
InstanceSerializer
(
instances
,
many
=
True
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
elif
request
.
method
==
'POST'
:
data
=
JSONParser
()
.
parse
(
request
)
serializer
=
InstanceSerializer
(
data
=
data
)
if
serializer
.
is_valid
():
serializer
.
save
()
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
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