def post(self, request): serializer = JournalistSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request): journalists = Journalist.objects.all() serializer = JournalistSerializer(journalists, many=True, context={"request": request}) return Response(serializer.data)
def get(self, request): journalists = Journalist.objects.all() # Set many=True since articles is a QuerySet of mulitiple articles serializer = JournalistSerializer(journalists, many=True) return Response(serializer.data)
def get(self, request, pk): journalist = get_object_or_404(Journalist, pk=pk) serializer = JournalistSerializer(journalist, context={'request': request}) return Response(serializer.data)
def get(self, request, pk): journalist = self.get_object(pk) serializer = JournalistSerializer(journalist) return Response(serializer.data)