Explorar el Código

Representative API

master
kj1352 hace 3 años
padre
commit
e4ac223186
Se han modificado 8 ficheros con 56 adiciones y 11 borrados
  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 Ver fichero

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




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

+ 2
- 2
project/views.py Ver fichero

@@ -3,7 +3,7 @@ from rest_framework.views import APIView
from rest_framework.authentication import TokenAuthentication, SessionAuthentication from rest_framework.authentication import TokenAuthentication, SessionAuthentication
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from .models import Project from .models import Project
from .serializers import ProjectSerializers
from .serializers import ProjectSerializer




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


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

+ 3
- 1
representative/admin.py Ver fichero

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


# Register your models here.

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

+ 1
- 4
representative/models.py Ver fichero

@@ -17,7 +17,4 @@ class Representative(models.Model):
phone = PhoneNumberField() phone = PhoneNumberField()
role = models.ForeignKey(Role, on_delete=models.CASCADE) role = models.ForeignKey(Role, on_delete=models.CASCADE)
projects = models.ManyToManyField(Project) 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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -6,6 +6,7 @@ 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 from project import urls as projectUrls
from representative import urls as representativeUrls




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