Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django partial update

I have two threads, one which runs something like update t set ColA=foo and the other runs update t set ColB=foo. If they were doing raw SQL statements there would be no contention, but since Django gets and saves the entire row, a race condition can occur.

Is there any way to tell Django that I just want to save a certain column?

like image 393
Xodarap Avatar asked Dec 22 '22 08:12

Xodarap


1 Answers

Update old topic.

Now, we have update_fields argument with save:

If save() is passed a list of field names in keyword argument update_fields, only the fields named in that list will be updated.

https://docs.djangoproject.com/en/stable/ref/models/instances/#specifying-which-fields-to-save

product.name = 'Name changed again'
product.save(update_fields=['name'])
like image 74
LennyLip Avatar answered Jan 03 '23 04:01

LennyLip