Re: Atomic IntegerField increment based on another model instance

2019-06-02 Thread Ryan Causey
The solution I ended up going with was using a PostgreSQL table lock: @contextmanager @transaction.atomic def lock_table(model): """Performs a table lock on the provided model. Note that this locks the entire table for the given model and prevents any other operations from occurring on that model.

Atomic IntegerField increment based on another model instance

2019-06-01 Thread Ryan Causey
Assume the following models for this question: class Jurisdiction(models.Model): name = models.CharField(max_length = 100) class Account(models.Model): account_number = models.PositiveIntegerField(blank = True) jurisdiction = models.ForeignKey("Jurisdiction", on_delete = models. CASCA