add: add new api
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
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.response import Response
|
||||
@@ -16,13 +16,15 @@ class ProjectListApiView(generics.ListAPIView):
|
||||
permission_classes = [HasRolePermission]
|
||||
pagination_class = CustomPageNumberPagination
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
Project.objects
|
||||
.select_related('location')
|
||||
.exclude(is_archive=True)
|
||||
.exclude(folder__isnull=False)
|
||||
)
|
||||
def get(self, request):
|
||||
mine = request.query_params.get('is_mine')
|
||||
queryset = Project.objects.select_related('location').exclude(is_archive=True).exclude(folder__isnull=False)
|
||||
if mine and mine.lower() == 'true':
|
||||
queryset = queryset.filter(Q(boss=request.user) | Q(foreman=request.user) | Q(other_members=request.user))
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user