假設(shè)我有一個模型:我有一些物品:grocery = {
status : True,
fruits: ['1', '23', '55'],
comments: {'1': "test", '23': "test2", '55': ""}我有一個粗略的潛在 Django 更新查詢:Fruit.objects.all().filter(id__in=grocery.get('fruits')).update(status=grocery.get('status'), comment=grocery.get('comments'))我已成功更新狀態(tài),但我想動態(tài)更新注釋,以便如果有問題的 Fruit 對象具有,例如,id: 23水果注釋將為test2,或者如果該對象具有'id: 55'它將是''
1 回答

慕村9548890
TA貢獻1884條經(jīng)驗 獲得超4個贊
不確定確切的語法,但我想到的是這樣的:
for f in Fruit.objects.filter(id__in=grocery.get('fruits')) : f.update(status=grocery.get('status'), comment=grocery['comments'][f.id])
添加回答
舉報
0/150
提交
取消