Reputation: 1021
Let's say I have a model:
I have some items:
grocery = {
status : True,
fruits: ['1', '23', '55'],
comments: {'1': "test", '23': "test2", '55': ""}
I have a rough potential Django update query:
Fruit.objects.all().filter(id__in=grocery.get('fruits')).update(status=grocery.get('status'), comment=grocery.get('comments'))
I'm successfully updating the status but I want to dynamically update the comments so that if the Fruit object in question has, for example, id: 23
, the fruit comment will be test2
, or if the object has 'id: 55'
it will be ''
Upvotes: 0
Views: 1478
Reputation: 302
Not sure of the exact syntax but i think of something like this:
for f in Fruit.objects.filter(id__in=grocery.get('fruits')) :
f.update(status=grocery.get('status'), comment=grocery['comments'][f.id])
Upvotes: 1