How to use “select_for_update()” to get an object in Django?

Just call get, slice it, etc. and save as usual. The lock is in place through the transaction.

ob = MyModel.objects.select_for_update().get(pk=1)

Any changes are committed at the end of the transaction (which by default through 1.5 is per-request)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)