I have Model, e.g.:
class Example(models.Model):
title = models.SlugField()
version = models.PositiveSmallIntegerField(default=0)
content = models.TextField(blank=True)
class Meta:
unique_together = (
('title', 'version'),
)
I would like to achieve something like that below but somehow avoid race conditions and make this atomic:
e = Example(title='test')
e.version = Example.objects.filter(title=e.title).aggregate(Max('version'))['version__max']+1
e.save()
PS. I'm using Django 1.8
I'm overriding
.save()
like so:(Adjust as necessary for your validation story)