Bläddra i källkod

Representative API

master
kj1352 3 år sedan
förälder
incheckning
e4ac223186
8 ändrade filer med 56 tillägg och 11 borttagningar
  1. +1
    -1
      project/serializers.py
  2. +2
    -2
      project/views.py
  3. +3
    -1
      representative/admin.py
  4. +1
    -4
      representative/models.py
  5. +14
    -0
      representative/serializers.py
  6. +7
    -0
      representative/urls.py
  7. +25
    -2
      representative/views.py
  8. +3
    -1
      workx_backend/urls.py

+ 1
- 1
project/serializers.py Visa fil

@@ -2,7 +2,7 @@ from rest_framework import serializers
from .models import Project


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

+ 2
- 2
project/views.py Visa fil

@@ -3,7 +3,7 @@ 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
from .serializers import ProjectSerializer


class ProjectList(APIView):
@@ -12,5 +12,5 @@ class ProjectList(APIView):

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

+ 3
- 1
representative/admin.py Visa fil

@@ -1,3 +1,5 @@
from django.contrib import admin
from .models import *

# Register your models here.

admin.site.register([Representative, Role])

+ 1
- 4
representative/models.py Visa fil

@@ -17,7 +17,4 @@ class Representative(models.Model):
phone = PhoneNumberField()
role = models.ForeignKey(Role, on_delete=models.CASCADE)
projects = models.ManyToManyField(Project)
clients = models.ForeignKey(Client, on_delete=models.CASCADE)

def __str__(self):
return self.user.name
client = models.ForeignKey(Client, on_delete=models.CASCADE)

+ 14
- 0
representative/serializers.py Visa fil

@@ -0,0 +1,14 @@
from rest_framework import serializers
from .models import Role, Representative


class RoleSerializer(serializers.ModelSerializer):
class Meta:
model = Role
fields = ['id', 'name']


class RepresentativeSerializer(serializers.ModelSerializer):
class Meta:
model = Representative
fields = ['id', 'user', 'phone', 'role', 'projects', 'client']

+ 7
- 0
representative/urls.py Visa fil

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

urlpatterns = [
path('representative-roles/', views.RoleList.as_view()),
path('representatives/', views.RepresentativeList.as_view()),
]

+ 25
- 2
representative/views.py Visa fil

@@ -1,3 +1,26 @@
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 Representative, Role
from .serializers import RoleSerializer, RepresentativeSerializer

# Create your views here.

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

def get(self, request):
roles = Role.objects.all()
serializer = RoleSerializer(roles, many=True)
return Response(serializer.data)


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

def get(self, request):
representatives = Representative.objects.all()
serializer = RepresentativeSerializer(representatives, many=True)
return Response(serializer.data)

+ 3
- 1
workx_backend/urls.py Visa fil

@@ -6,6 +6,7 @@ from drf_yasg import openapi
from client import urls as clientUrls
from employee import urls as employeeUrls
from project import urls as projectUrls
from representative import urls as representativeUrls


schema_view = get_schema_view(
@@ -31,7 +32,8 @@ urlpatterns = [
path('api/', include([
path('', include(clientUrls)),
path('', include(employeeUrls)),
path('', include(projectUrls))
path('', include(projectUrls)),
path('', include(representativeUrls))
]))
])),
]