def put(self, request, recipe_id): recipe = get_object_or_404(Recipe, pk=recipe_id) serializer = RecipeSerializer(instance=recipe, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response({'errors': serializer.errors})
def post(self, request): serializer = RecipeSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response({'error': serializer.errors}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)