Exemple #1
0
 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)
Exemple #2
0
 def get(self, request):
     journalists = Journalist.objects.all()
     serializer = JournalistSerializer(journalists,
                                       many=True,
                                       context={"request": request})
     return Response(serializer.data)
Exemple #3
0
 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)
Exemple #4
0
 def get(self, request, pk):
     journalist = get_object_or_404(Journalist, pk=pk)
     serializer = JournalistSerializer(journalist,
                                       context={'request': request})
     return Response(serializer.data)
Exemple #5
0
 def get(self, request, pk):
     journalist = self.get_object(pk)
     serializer = JournalistSerializer(journalist)
     return Response(serializer.data)