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): 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)
def retrieve(self, request, pk=None): product = get_object_or_404(Product, pk=pk) slr = ProductSerializer(product, context={'request': request}) return Response(slr.data)
def list(self, request): objects = Product.objects.all() slr = ProductSerializer(objects, many=True, context={'request': request}) return Response(slr.data)