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)
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)