在/ api / customer / order / add /

时间:2018-07-16 06:04:22

标签: python-3.x postman

我正在尝试将一个具有访问令牌的对象添加到邮递员,该访问令牌是我从https://developers.facebook.com/tools/accesstoken/获得的,

“ RelatedObjectDoesNotExist位于/​​ api / customer / order / add /

这是urls.py

url(r'^api/customer/order/add/$', apis.customer_add_order),

这是apis.py

if request.method == "POST":
        # Get token
        access_token = AccessToken.objects.get(token = request.POST.get("access_token"),
            expires__gt = timezone.now())

        #Get profile
        customer = access_token.user.customer

        #Check whether customer has any order that is not delivered
        if Order.objects.filter(customer = customer).exclude(status = Order.DELIVERED):
            return JsonResponse({"status": "failed", "error": "Your last order must be completed."})

        # Check address
        if not request.POST["address"]:
            return JsonResponse({"status": "failed", "error": "Adress is required."})

        #Get Order Details
        order_details = json.loads(request.POST["order_details"])

        order_total = 0
        for meal in order_details:
            order_total += Meal.objects.get(id = meal["meal_id"]).price * meal["quantity"]

        if len(order_details) > 0:
            # Step 1 - Create an Order
            order = Order.objects.create(
                customer = customer,
                restaurant_id = request.POST["restaurant_id"],
                total = order_total,
                status = Order.COOKING,
                address = request.POST["address"]
            )

            # Step 2 - Create Order details
            for meal in order_details:
                OrderDetails.objects.create(
                    order = order,
                    meal_id = meal["meal_id"],
                    quantity = meal["quantity"],
                    sub_total = Meal.objects.get(id = meal["meal_id"]).price * meal["quantity"]
                )

            return JsonResponse({"status": "success"})

postman error massage

任何解决方法的想法。

0 个答案:

没有答案