add: add new api
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.db.models import Prefetch
|
from django.db.models import Prefetch, Q
|
||||||
|
|
||||||
from rest_framework import generics, status, views
|
from rest_framework import generics, status, views
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
@@ -16,13 +16,15 @@ class ProjectListApiView(generics.ListAPIView):
|
|||||||
permission_classes = [HasRolePermission]
|
permission_classes = [HasRolePermission]
|
||||||
pagination_class = CustomPageNumberPagination
|
pagination_class = CustomPageNumberPagination
|
||||||
|
|
||||||
def get_queryset(self):
|
def get(self, request):
|
||||||
return (
|
mine = request.query_params.get('is_mine')
|
||||||
Project.objects
|
queryset = Project.objects.select_related('location').exclude(is_archive=True).exclude(folder__isnull=False)
|
||||||
.select_related('location')
|
if mine and mine.lower() == 'true':
|
||||||
.exclude(is_archive=True)
|
queryset = queryset.filter(Q(boss=request.user) | Q(foreman=request.user) | Q(other_members=request.user))
|
||||||
.exclude(folder__isnull=False)
|
page = self.paginate_queryset(queryset)
|
||||||
)
|
if page is not None:
|
||||||
|
serializer = self.serializer_class(page, many=True)
|
||||||
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class ArchivedProjectListApiView(generics.ListAPIView):
|
class ArchivedProjectListApiView(generics.ListAPIView):
|
||||||
|
|||||||
Reference in New Issue
Block a user