本文整理汇总了Python中orders.models.Order.get_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python Order.get_or_create方法的具体用法?Python Order.get_or_create怎么用?Python Order.get_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orders.models.Order
的用法示例。
在下文中一共展示了Order.get_or_create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_cart
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import get_or_create [as 别名]
def update_cart(request):
"""Updates the user's shopping cart."""
order = Order.get_or_create(request)
order_form = OrderForm(request.REQUEST, prefix='btb', instance=order)
if order_form.is_valid():
order = order_form.save()
return order.get_as_cart()
return False
示例2: remove
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import get_or_create [as 别名]
def remove(request, product_slug=None):
"""Remove a product from the cart."""
product = get_object_or_404(Product.objects.active(), slug=product_slug)
order = Order.get_or_create(request)
# Delete the product from the order
product_in_order = get_object_or_404(ProductInOrder,
product=product, order=order)
product_in_order.delete()
messages.success(request, 'Removed "%s" from your cart.' % product.name)
# Redirect to the shopping cart
return HttpResponseRedirect(reverse('orders.views.cart'))
示例3: cart
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import get_or_create [as 别名]
def cart(request):
"""View and edit the user's shopping cart."""
order = Order.get_or_create(request)
order_form = OrderForm(prefix='btb', instance=order)
# if request.method == 'POST':
# order_form = OrderForm(request.REQUEST, prefix='btb', instance=order)
# if order_form.is_valid():
# order_form.save()
# return HttpResponseRedirect(reverse('orders.views.purchase'))
cart = order.get_as_cart()
return render_to_response('orders/cart.html', {
'cart': cart,
'order_form': order_form,
'paypal_post_url': settings.PAYPAL_POST_URL,
'paypal_business': settings.PAYPAL_BUSINESS,
'paypal_currency_code': settings.PAYPAL_CURRENCY_CODE,
'paypal_invoice_id': order.invoice_id,
'paypal_return_url': reverse('paypal.views.paypal_return'),
'paypal_cancel_return_url': reverse('paypal.views.paypal_cancel_return'),
}, context_instance=RequestContext(request))
示例4: add
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import get_or_create [as 别名]
def add(request, product_slug=None):
"""Add a product to the cart."""
product = get_object_or_404(Product.objects.active(), slug=product_slug)
order = Order.get_or_create(request)
if product.can_be_purchased():
# Check if the product is already in the order
product_in_order = order.productinorder_set.filter(product=product).all()
if len(product_in_order):
# Disallow adding more than one of any product
messages.warning(request, 'You can only add one of each product to your cart.')
# # Add 1 to the quantity of that product
# product_in_order = product_in_order[0]
# product_in_order.quantity += 1
# messages.success(request, 'Added another "%s" to your cart.' % product.name)
else:
# Add the product to the order
product_in_order = ProductInOrder(order=order, product=product)
messages.success(request, 'Added "%s" to your cart.' % product.name)
product_in_order.save()
else:
messages.error(request, 'This product is not currently available for purchase.')
# Redirect to the shopping cart
return HttpResponseRedirect(reverse('orders.views.cart'))
示例5: current_order
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import get_or_create [as 别名]
def current_order(request):
"""Returns the active order from the session (creates one if necessary)."""
return {'current_order': Order.get_or_create(request)}