本文整理匯總了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