update multiple django id's at once
Solution 1:
Use __in
to query for all the items at once, instead of looping over the ids
ids = request.POST.getlist("id")
qs = fp.objects.filter(id__in=ids)
You can use the queryset's .update
method to update all items in the queryset at once.
P_350 = request.POST["P_350"]
P_450 = request.POST["P_450"]
updates = {}
if len(P_350) > 1:
updates['P_350'] = P_350
if len(P_450) > 1:
updates['P_450'] = P_450
if updates:
qs.update(**updates)