Пример #1
0
 def update(self, request, pk=None):
     try:
         item = Author.objects.get(pk=pk)
     except Author.DoesNotExist:
         return Response(status=404)
     serializer = AuthorSerializer(item, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=400)
Пример #2
0
 def create(self, request):
     serializer = AuthorSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=201)
     return Response(serializer.errors, status=400)