Answer the question
In order to leave comments, you need to log in
How to split get requests to get all objects and a specific one in APIView?
In most cases, you need to get a list of all faculties:
class FacultyView(APIView):
def get(self, request):
faculties = Faculty.objects.all()
serializer = FacultySerializer(
instance=faculties,
many=True
)
return Response(serializer.data)
Answer the question
In order to leave comments, you need to log in
To do this, viewsets came up with:
class FacultyViewSet(
mixins.ListModelMixin,
mixins.RetrieveModelMixin,
GenericViewSet
):
queryset = Faculty.objects.all()
serializer_class = FacultySerializer
permission_classes = (permissions.AllowAny, )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question