本文整理汇总了Python中cart.cart.Cart.update方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.update方法的具体用法?Python Cart.update怎么用?Python Cart.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.cart.Cart
的用法示例。
在下文中一共展示了Cart.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import update [as 别名]
def post(self, request, *args, **kwargs):
cart = Cart(self.request)
for item in cart:
quantity = request.POST.get('q_'+str(item.product.id), None)
if quantity is not None:
cart.update(item.product, quantity, item.product.price)
return redirect("cart")
示例2: show_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import update [as 别名]
def show_cart(request):
cart = Cart(request)
if request.method == 'POST':
postdata = request.POST.copy()
if postdata['submit'] == 'Remove':
item_id = postdata['item_id']
cart.remove(item_id = item_id)
if postdata['submit'] == 'Update':
item_id = postdata['item_id']
quantity = postdata['quantity']
cart.update(item_id = item_id, quantity=quantity)
return render(request, 'cart/cart.html',{'cart':cart})
示例3: change_in_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import update [as 别名]
def change_in_cart(request, product_id, quantity):
if int(quantity) > 0:
product = MenuItem.objects.get(id=product_id)
cart = Cart(request)
batch_item = Menu.get_current_menu().itembatch_set.get(item=product)
if batch_item.amount >= int(quantity):
cart.update(product, quantity, product.retailer_price(request.session['user']))
request.session['quantity_error'] = None
request.session['quantity_error_item'] = None
return JsonResponse({"return": "ok"})
else:
request.session['quantity_error'] = batch_item.amount
request.session['quantity_error_item'] = product
return JsonResponse({"return": "fail"})
else:
remove_from_cart(request, product_id)
示例4: update_item
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import update [as 别名]
def update_item(request, product_id):
cart = Cart(request)
product = get_object_or_404(Product, id=product_id)
form = CartItemForm(product, request.POST, prefix=str(product.pk))
if form.is_valid():
cd = form.cleaned_data
quantity = cd.get("quantity")
item = cart.update(product, int(quantity), product.price)
if request.is_ajax():
return JsonResponse(
{
"success": True,
"count": cart.cart.item_set.count(),
"product_id": product.pk,
"item_id": item.pk,
"quantity": str(quantity),
"row_sum": str(item.total_price).replace(".", ","),
"total_sum": str(cart.cart.total_sum).replace(".", ","),
}
)
return redirect("cart-show")