for _size in goods['sizes']: if Size.objects.filter(sname=_size[0]).count() == 1: size = Size.objects.get(sname=_size[0]) else: size = Size.objects.create(sname=_size[0]) sizes.append(size) colors = [] for _color in goods['colors']: color = Color.objects.create(colorname=_color[0], colorurl=_color[1]) colors.append(color) for _spec in goods['specs']: goodsdetails = GoodsDetailName.objects.create(gdname=_spec[0]) for img in _spec[1]: GoodDetail.objects.create(goods=good,goodsdname=goodsdetails,gdurl=img) for c in colors: for s in size: Inventory.objects.create(count=100,goods=good, color=c, sizes=s)TypeError: Inventory() got an unexpected keyword argument 'size'如何修正哪里
时间: 2023-06-17 14:08:59 浏览: 70
sql.rar_SPJ_SQL例程_city_site:www.pudn.com_数据库spj表
5星 · 资源好评率100%
根据错误提示,`Inventory` 模型中没有名为 `size` 的字段。你在创建 `Inventory` 对象时使用了 `size` 参数,导致出现了错误。
假设你的 `Inventory` 模型中有 `sizes` 字段,表示商品的尺码。那么你需要将创建 `Inventory` 对象时的参数名由 `size` 改为 `sizes`,即:
```
for c in colors:
for s in sizes:
Inventory.objects.create(count=100, goods=good, color=c, sizes=s)
```
这样就可以避免该错误了。
阅读全文