Example #1
0
def add_order(request):
    '''添加订单到数据库'''
    cart_list = request.POST.getlist('cart_list')
    total_price = request.POST.get('total_price', 0)

    user_id = request.session.get('user_id')

    order = OrderModel()
    order.user_id = user_id
    order.create_time = datetime.datetime.now()
    order.total_price = total_price
    order.is_pay = 0
    order.save()

    for cart_id in cart_list:
        cart = CartModel.objects.get(id=cart_id)

        order_goods = OrderGoodsModel()
        order_goods.goods_id = cart.goods.id
        order_goods.order_id = order.id
        order_goods.number = cart.count

        order_goods.save()
        # 订单信息和订单商品的信息保存完之后,删除购物车的商品
        cart.delete()
    return JsonResponse({'result': 'success'})
Example #2
0
def add_order(request):
    """添加订单到数据库"""

    cart_list = request.POST.getlist("cart_list")
    total_price = request.POST.get("total_price", 0)

    user_id = request.session.get("user_id")

    order = OrderModel()
    order.user_id = user_id
    order.create_time = datetime.datetime.now()
    order.total_price = total_price
    order.is_pay = 0
    order.save()

    for cart_id in cart_list:
        cart = CartModel.objects.get(id=cart_id)

        order_goods = OrderGoodsModel()
        order_goods.goods_id = cart.goods.id
        order_goods.order_id = order.id
        order_goods.number = cart.count

        order_goods.save()
        # 订单信息和订单对应的商品信息保存完毕,删除购物车中的商品
        cart.delete()
    return JsonResponse({"result": "success"})
Example #3
0
def add_order(request):
    """添加订单到数据库"""
    cart_list = request.POST.getlist('cart_list')

    total_price = request.POST.get('shifu')
    print(request.POST)
    user_id = request.session.get('user_id')

    order = OrderModel()
    order.user_id = user_id
    order.create_time = datetime.datetime.now()
    order.total_price = total_price
    order.is_pay = False
    order.save()

    for cart_id in cart_list:
        cart = CartModel.objects.get(id=cart_id)

        order_goods = OrderGoodsModel()
        order_goods.goods_id = cart.goods.id
        order_goods.order_id = order.id
        order_goods.number = cart.count

        order_goods.save()
        cart.delete()

    return JsonResponse({'result': 'success'})