当前位置: 首页>>代码示例>>Python>>正文


Python Order.username方法代码示例

本文整理汇总了Python中models.Order.username方法的典型用法代码示例。如果您正苦于以下问题:Python Order.username方法的具体用法?Python Order.username怎么用?Python Order.username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Order的用法示例。


在下文中一共展示了Order.username方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pay

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import username [as 别名]
def pay(request):
    """
    Do the "create order" thing.
    It get the CARD_ID_SESSION_KEY from session to get the items information that been added into cart by user.
    Then calling the cart_subtotal() function in cart_module to get the order total price.

    The shipping information will also be collected through html form.

    If every thing is fine, then create an order, else return error message.

    :param request:
    :return:
    """
    if request.method == 'POST':
        if request.session[CART_ID_SESSION_KEY] != '':
            cart_items = cart_module.get_cart_items(request)
            cart_subtotal = cart_module.cart_subtotal(request)
            shipping_zip = request.POST['shipping_zip']
            shipping_add = request.POST['shipping_add']
            shipping_to = request.POST['shipping_to']
            username = request.user.username
            cart_id = cart_items[0].cart_id

            try:
                order = Order.objects.get(cart_id = request.session[CART_ID_SESSION_KEY])
            except Order.DoesNotExist:
                order = None

            if order != None:
                order = Order.objects.get(cart_id=request.session[CART_ID_SESSION_KEY])
            else:
                order = Order()

            order.cart_id = cart_id
            order.shipping_add = shipping_add
            order.shipping_to = shipping_to
            order.shipping_zip = shipping_zip
            order.username = username
            order.total_price = cart_subtotal
            order.save()
            request.session[CART_ID_SESSION_KEY] = '' # delete session key
            return HttpResponseRedirect('/account/order/'+order.order_id+'/')
        else:
            return render(request, 'account/error.html',{'error':'This order has been created.' })
    else:
        return HttpResponseRedirect('/account/')
开发者ID:yuankunluo,项目名称:project_42_shopping_site,代码行数:48,代码来源:views.py


注:本文中的models.Order.username方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。