Exemplo n.º 1
0
 def create(self, request):
     user = request.user
     slr = ProductSerializer(data=request.data)
     if slr.is_valid():
         product = slr.save()
         return Response(slr.data)
     else:
         return Response(slr.errors, status=400)
Exemplo n.º 2
0
 def update(self, request, pk=None):
     product = get_object_or_404(Product, pk=pk)
     slr = ProductSerializer(data=request.data, instance=product)
     if slr.is_valid():
         product = slr.save()
         return Response(slr.data)
     else:
         return Response(slr.errors, status=400)
 def create(self, request):
     slr = ProductSerializer(data=request.data,
                             context={'request': request})
     if slr.is_valid():
         product = slr.save()
         return Response(slr.data)
     else:
         return Response(slr.errors, status=400)