本文整理汇总了Python中products.models.Product.__dict__[key]方法的典型用法代码示例。如果您正苦于以下问题:Python Product.__dict__[key]方法的具体用法?Python Product.__dict__[key]怎么用?Python Product.__dict__[key]使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类products.models.Product
的用法示例。
在下文中一共展示了Product.__dict__[key]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import __dict__[key] [as 别名]
def handle(self, **options):
product_json = get_json()
for item in product_json:
# Try to find product - if it doesn't exist, create a new DB entry
try:
product = Product.objects.get(pk=item["id"])
except Product.DoesNotExist:
product = Product()
for key, value in item.items():
if not key in ["sizes"]:
if key in ["price", "price_old"]:
product.__dict__[key] = value.replace(",", ".")
elif key in ["kids", "kid_adult", "women", "free_porto"]:
product.__dict__[key] = int(value)
else:
product.__dict__[key] = value
product.from_json = True
product.save()
# Create a list of product sizes from the json
product_sizes = item["sizes"].split(",")
# Create product sizes, and add the sizes to the product
for item in product_sizes:
size, created = ProductSize.objects.get_or_create(title=item)
product.sizes.add(size)
return None