开发者

How to do a "while quantity is greater than zero loop"

开发者 https://www.devze.com 2023-03-05 12:10 出处:网络
So I am using a gift certificate module with satchmo store and in order to send multiple gift certificate codes equal to the number of items purchased I need to add a loop doing

So I am using a gift certificate module with satchmo store and in order to send multiple gift certificate codes equal to the number of items purchased I need to add a loop doing

"while quantity is greater than zero loop"

Here is the code, the loop is being added to right before "price=order_item.unit_price"

 def order_success(self, order,
 order_item):
         log.debug("Order success called, creating gift certs on order:
 %s", order)
         message = ""
         email = ""
         for detl in order_item.orderitemdetail_set.all():
             if detl.name == "email":
                 email = detl.value
             elif detl.name == "message":
                 message = detl.value

         price=order_item.unit_price
         log.debug("Creating gc for %s", price)
         gc = GiftCertificate(
             or开发者_如何转开发der = order,
             start_balance= price,
             purchased_by = order.contact,
             valid=True,
             message=message,
             recipient_email=email
             )
         gc.save()


I am not sure I understand the question, but maybe something like

for ix in range(0, order_item.quantity):
  ... do stuff

might do the trick. You don't have to use the ix anywhere inside the loop, it is just (arguably) the standard way to do something n times in Python.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号