コード例 #1
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)
コード例 #2
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)
 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)
コード例 #4
0
 def retrieve(self, request, pk=None):
     product = get_object_or_404(Product, pk=pk)
     slr = ProductSerializer(product, context={'request': request})
     return Response(slr.data)
コード例 #5
0
 def list(self, request):
     objects = Product.objects.all()
     slr = ProductSerializer(objects,
                             many=True,
                             context={'request': request})
     return Response(slr.data)