本文整理汇总了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()