You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

25 lines
862 B

from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
from ..models import Project
from ..permissions import IsInProjectReadOnlyOrAdmin
from ..serializers import ProjectPolymorphicSerializer, ProjectSerializer
class ProjectList(generics.ListCreateAPIView):
serializer_class = ProjectPolymorphicSerializer
pagination_class = None
permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin]
def get_queryset(self):
return self.request.user.projects
def perform_create(self, serializer):
serializer.save(users=[self.request.user])
class ProjectDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Project.objects.all()
serializer_class = ProjectSerializer
lookup_url_kwarg = 'project_id'
permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin]