现在我正在这样做:
for product in request.session['productList']:
productData = Products_model(
Fk_Cat_id=product['cat'],
Fk_supplier_id=product['supplier'],
Name=product['name'],
Price=product['price'],
)
productData.save()
print 'All products has been saved'
但也许有类似的东西:
productData = Products_model.dictionary.(request.session['productList'])
productData.save()
谢谢!
答案 0 :(得分:0)
如果您可以更改字典,以便键名与模型参数的名称匹配
products = [Products_model(**data) for data in request.session['productList']]
Products_model.objects.bulk_create(products)