【发布时间】:2021-05-02 20:30:30
【问题描述】:
你好同事我想知道这个对象列表是否可以从我展示的脚本中保存,我想从 django shell 执行它
python3 manage.py shell < script.py
以下是我的脚本
from orders_management.models import Products
objects = [
'Products(name = "destornillador", section = "ferrreteria", price = 35)',
'Products(name = "balon", section = "deportes", price = 25)',
'Products(name = "raqueta", section = "deportes", price = 105)',
'Products(name = "muneca", section = "juguetes", price = 15)',
'Products(name = "tren electrico", section = "jugueteria", price = 135)',
]
for object in objects:
my_product = object
my_product.save()
它显示给我的错误
File "<string>", line 15, in <module>
AttributeError: 'str' object has no attribute 'save'
【问题讨论】: