Insertion command via an API (Django project)

I am developing an e-commerce site using API calls. I would like to insert orders, the idea is after having selected several products on the cart (assume 4 products), I would like to insert them using the API only once, not with a loop. That is to say, I call the API only once and this inserts the 04 products into the database. And not put the API call in the shopping cart session loop, which will call the url 4 times. API

Noted that if I remove its rows from the loop, it only inserts the last product

url='http://myAPI/Product/postProduct'
x=requests.post(url,json=data)

Views.py

@login_required
def postCommande(request):
  for key,value in request.session.get("cart", {}).items():
     data={
     'my_commande':[
        {
            'date':str(datetime.now()),
            'name': request.user.client.name,
            'content':[
                {
                    'article':value.get('product_id'),
                    'designation':value.get('name'),
                    'quantite':value.get('quantity')
                }
            ]
         }
       ]
      }
     url='http://myAPI/Product/postProduct'
     x=requests.post(url,json=data)
Back to Top