develop #8
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
rest-app/smartpicasso/app/project/serializers.py
Normal file
17
rest-app/smartpicasso/app/project/serializers.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
"""
|
||||||
|
@author p.dolata
|
||||||
|
"""
|
||||||
|
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from smartpicasso.app.project.models import Project
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectSerializer(serializers.ModelSerializer):
|
||||||
|
"""
|
||||||
|
Class to manage serializing Project
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Project
|
||||||
|
fields = ('id', 'name', 'created_at', 'updated_at')
|
11
rest-app/smartpicasso/app/project/urls.py
Normal file
11
rest-app/smartpicasso/app/project/urls.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
"""
|
||||||
|
@author: p.dolata
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
from smartpicasso.app.project.views import ProjectsView
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r'^projects', ProjectsView.as_view(), name='projects')
|
||||||
|
]
|
@ -1,3 +1,32 @@
|
|||||||
from django.shortcuts import render
|
"""
|
||||||
|
@author p.dolata
|
||||||
|
"""
|
||||||
|
|
||||||
# Create your views here.
|
from rest_framework import status
|
||||||
|
from rest_framework.generics import CreateAPIView
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from smartpicasso.app.project.serializers import ProjectSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectsView(CreateAPIView):
|
||||||
|
"""
|
||||||
|
View for project endpoints
|
||||||
|
"""
|
||||||
|
permission_classes = (IsAuthenticated,)
|
||||||
|
serializer_class = ProjectSerializer
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
serializer = self.serializer_class(data=request.data)
|
||||||
|
serializer.is_valid(raise_exception=True)
|
||||||
|
project = serializer.save(user=request.user)
|
||||||
|
status_code = status.HTTP_201_CREATED
|
||||||
|
response = {
|
||||||
|
'success': 'True',
|
||||||
|
'status_code': status_code,
|
||||||
|
'data': {
|
||||||
|
'id': project.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Response(response, status=status_code)
|
||||||
|
@ -19,5 +19,6 @@ from django.urls import path, include
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('api/', include('smartpicasso.app.user.urls')),
|
path('api/', include('smartpicasso.app.user.urls')),
|
||||||
path('api/', include('smartpicasso.app.user_profile.urls')),
|
path('api/', include('smartpicasso.app.user_profile.urls')),
|
||||||
|
path('api/', include('smartpicasso.app.project.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user