--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHLKn731GXi2A2i3-7DkVaPrD1Ta%2Bu%2B-ccjK7bA0uW4gdsHjJA%40mail.gmail.com.
class CartViewSet(viewsets.ModelViewSet):
serializer_class = CartDetailSerializer
queryset = CartList.objects.all()
#@detail_route(methods=['post', 'put'])
def add_item(request, self, pk=None):
cart = self.get_object()
try:
product = Product.objects.get(
pk = request.data['product_id']
)
quantity = int(request.data['quantity'])
except Exception as e:
print (e)
return Response({'status': 'fail' })
if product.quantity < 0 or product.quantity - quantity < 0:
print('sorry check back leta')
return Response({'status': 'fail'})
existing_cart = CartList.objects.filter(product=product,
cart=cart).first()
if existing_cart:
existing_cart.quantity +=quantity
existing_cart.save()
else:
new_cart = CartList(cart=cart, product=product,
quantity=quantity)
new_cart.save()
product_list =
Product.Objects.filter(manufacturer=manufacturer).count()
serializer = CartSerializer(cart)
return Response(serializer.data)
class CartDetailSerializer(serializers.ModelSerializer):
customer = UserSerializer(read_only =True)
items = serializers.StringRelatedField(many=True)
class Meta:
model = CartList
fields = ('id', 'customer', 'items', 'created', 'updated')
class CartListSerializer(serializers.ModelSerializer):
class Meta:
model = CartList
fields = ('product', 'quantity')
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cf4ed839-2cd7-4517-b3d1-b51b3c7a89ee%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c8a99cd5-7e52-459f-9f17-8d9e5272c963%40googlegroups.com.