There is a queue of tasks for humans. I want to take one unfulfilled task from the queue and assign an executor. I use update()
and nested query to prevent a race condition.
sliced_queryset = Tasks.objects.filter(done=False, executor__isnull=True)[:1]
task = Tasks.objects.filter(id__in=sliced_queryset).update(executor=request.user)
update()
returns the number of rows matched. I want to have updated object in task
variable. Any ideas?