Reputation: 214
Within Django, I can't update the database even though all is correct.(I assume :) )
Should I proceed with query "get" instead of "filter" and use "save" instead of "update" ? In my database I have P_350 and P_450 columns. I am getting no error and also nothing is updated
for thing_id, values_dict in groups.items():
for value_id, value_value in values_dict.items():
qs = RFP.objects.filter(id__in=thing_id)
updates = {}
if value_id == '350':
if len(value_value) > 1:
updates['P_350'] = value_value
if value_id == '450':
if len(value_value) > 1:
updates['P_450'] = value_value
if updates:
qs.update(**updates)
Here is the prints for the groups.items:
397 350 try_3
397 450 try_4
370 350 try_1
370 450 try_2
Upvotes: 1
Views: 107
Reputation: 1991
you should try qs = RFP.objects.filter(id=thing_id)
instead of qs = RFP.objects.filter(id__in=thing_id)
. the __in
is looking for list of ids and you are providing a string and it will treat the string as a list instead.
Upvotes: 1