當前位置: 首頁>>代碼示例>>Python>>正文


Python Order.get_or_create方法代碼示例

本文整理匯總了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
開發者ID:skotcarruth,項目名稱:buybay,代碼行數:10,代碼來源:views.py

示例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'))
開發者ID:skotcarruth,項目名稱:buybay,代碼行數:15,代碼來源:views.py

示例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))
開發者ID:skotcarruth,項目名稱:buybay,代碼行數:25,代碼來源:views.py

示例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'))
開發者ID:skotcarruth,項目名稱:buybay,代碼行數:26,代碼來源:views.py

示例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)}
開發者ID:skotcarruth,項目名稱:buybay,代碼行數:5,代碼來源:context_processors.py


注:本文中的orders.models.Order.get_or_create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。