浏览代码

Project API

master
kj1352 3 年前
父节点
当前提交
20664e6fff
共有 4 个文件被更改,包括 32 次插入3 次删除
  1. +8
    -0
      project/serializers.py
  2. +6
    -0
      project/urls.py
  3. +15
    -2
      project/views.py
  4. +3
    -1
      workx_backend/urls.py

+ 8
- 0
project/serializers.py 查看文件

@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Project


class ProjectSerializers(serializers.ModelSerializer):
class Meta:
model = Project
fields = ['id', 'name', 'project_image', 'client', 'total_compensation', 'start_date', 'end_date']

+ 6
- 0
project/urls.py 查看文件

@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path('projects/', views.ProjectList.as_view()),
]

+ 15
- 2
project/views.py 查看文件

@@ -1,3 +1,16 @@
from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.authentication import TokenAuthentication, SessionAuthentication
from rest_framework.permissions import IsAuthenticated
from .models import Project
from .serializers import ProjectSerializers


# Create your views here.

class ProjectList(APIView):
authentication_classes = [TokenAuthentication, SessionAuthentication]
permission_classes = [IsAuthenticated]

def get(self, request):
projects = Project.objects.all()
serializer = ProjectSerializers(projects, many=True)
return Response(serializer.data)

+ 3
- 1
workx_backend/urls.py 查看文件

@@ -5,6 +5,7 @@ from drf_yasg.views import get_schema_view
from drf_yasg import openapi from drf_yasg import openapi
from client import urls as clientUrls from client import urls as clientUrls
from employee import urls as employeeUrls from employee import urls as employeeUrls
from project import urls as projectUrls




schema_view = get_schema_view( schema_view = get_schema_view(
@@ -29,7 +30,8 @@ urlpatterns = [
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('api/', include([ path('api/', include([
path('', include(clientUrls)), path('', include(clientUrls)),
path('', include(employeeUrls))
path('', include(employeeUrls)),
path('', include(projectUrls))
])) ]))
])), ])),
] ]