Пример #1
0
 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})
Пример #2
0
 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)