本文整理匯總了Python中models.Stock.update方法的典型用法代碼示例。如果您正苦於以下問題:Python Stock.update方法的具體用法?Python Stock.update怎麽用?Python Stock.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Stock
的用法示例。
在下文中一共展示了Stock.update方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: edit_stock
# 需要導入模塊: from models import Stock [as 別名]
# 或者: from models.Stock import update [as 別名]
def edit_stock(pk_id, stock_id, description, quantity, category, price):
"""Takes all stock arguments and save it in the selected stock record. (EDIT THE STOCK)
pk_id: primary key id, or stock to be edited.
The rest of the arguments are going to be the new data to the specified record.
"""
stock = Stock.update(
stock_id=stock_id, description=description,
quantity=quantity, category=category, price=price
).where(
Stock.id == pk_id
)
return stock.execute()
示例2: add_existing_stock
# 需要導入模塊: from models import Stock [as 別名]
# 或者: from models.Stock import update [as 別名]
def add_existing_stock(pk_id, to_add):
"""Increase quantity for a specified record by pk_id.
pk_id: primary key id
"""
stock = Stock.get(
Stock.id == pk_id
)
current_quantity = stock.quantity
new_quantity = current_quantity + to_add
query = Stock.update(
quantity=new_quantity
).where(
Stock.id == pk_id
)
return query.execute()