[Answered ]-Django – assign a single record from a queryset to a user and update it. Only releasing the record to another user if the transaction fails

1👍

This isn’t really working. It just gives the same product from the QuerySet and assigns it to all users currently visiting the url

This view doesn’t change the already_picked attribute of the Product it selects, so this will show the same Product to everyone.

I read something about the Django function select_for_update() but I don’t get my head wrapped around what it does. Is this something I might use to "lock" the first product to the first user while is busy looking for the product in the warehouse?

Yes, that’s correct. select_for_update() can be used to lock rows for a short period of time while you mark them as being picked. Also note the skip_locked parameter to that function, which can be used to tell the database that if the select encounters a locked row, it should skip it instead of waiting for the row to become available.

Leave a comment