本文整理汇总了Python中models.Item.quantity方法的典型用法代码示例。如果您正苦于以下问题:Python Item.quantity方法的具体用法?Python Item.quantity怎么用?Python Item.quantity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.quantity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_item_in_database
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import quantity [as 别名]
def _create_item_in_database(self, cart, product, quantity=1,
unit_price=Decimal("100")):
"""
Helper function so I don't repeat myself
"""
item = Item()
item.cart = cart
item.product = product
item.quantity = quantity
item.unit_price = unit_price
item.save()
return item
示例2: add_inventory_item_json
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import quantity [as 别名]
def add_inventory_item_json(data):
name = data['name']
description = data['description']
quantity = int(data['quantity'])
price = int(data['price'])
item = Item.query.filter_by(name=name).first()
if item is None:
item = Item(name=name, description=description, quantity=quantity,
price=price)
db.session.add(item)
else:
item.name = name
item.quantity = quantity
item.price = price
if description != "":
item.description = description
db.session.commit()
return jsonify(status="success")
示例3: add_inventory_item_html
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import quantity [as 别名]
def add_inventory_item_html(form):
name = form.name.data.strip()
description = form.description.data.strip()
quantity = form.quantity.data
price = form.price.data
item = Item.query.filter_by(name=name).first()
if item is None:
item = Item(name=name, description=description, quantity=quantity,
price=price)
db.session.add(item)
else:
item.name = name
item.quantity = quantity
item.price = price
if description != "":
item.description = description
db.session.commit()
return True
示例4: save
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import quantity [as 别名]
def save(cls, request: Request, *args, **kwargs):
""" Метод для сохранения товара
:param request:
:param kwargs:
:return:
"""
if request.get("id", False):
item = catalog.get_item(int(request.get("id")))
else:
item = Item()
item.title = request.get("title")
item.article = request.get("article")
item.short = request.get("short")
item.imgs = request.get("imgs", [])
item.body = request.get("body", "")
item.tags = request.get("tags", [])
item.categories = request.get("categories", [])
item.cost = int(request.get("cost", 0)) if str(request.get("cost")).isnumeric() else None
item.discount = int(request.get("discount")) if str(request.get("discount")).isnumeric() else None
item.quantity = int(request.get("quantity")) if str(request.get("quantity")).isnumeric() else None
item.set_attributes(request.get("attributes", []))
return {"item_id": item.save()}