python - How to pick one element from database atomically? -
i have django application simple model:
class thingtopick(models.model): title = models.charfield(max_length=200) start_date = models.datetimefield('date published', auto_now=true) status = models.integerfield(default=0) filedata = models.textfield()
the on view have:
exec_item = thingtorun.objects.filter(status=0).order_by('start_date')[0] exec_item.status = 1 exec_item.save()
i need way pick each thingtorun
1 , 1 concurrent user. know broken, how can prepare it?
what want here not picking something, picking , marking in process no-one else picks in meantime. method want select_for_update
:
exec_item = thingtorun.objects.select_for_update().filter(status=0).order_by('start_date')[0] exec_item.status = 1 exec_item.save() ...process exec_item ....
python django transactions
No comments:
Post a Comment