For next two models:
class Foo(models.Model):
parent = models.ForeignKey(Parent)
name = models.CharField()
class Bar(models.Model):
foreign = models.ForeignKey(Foo)
value = models.CharField(max_length=20)
I need to have unique_together constraint for Bar
model:
class Meta:
unique_together = ('value', 'foreign__parent')
Which is impossible in Django.
But is it possible to achieve this on database level (Postgresql) with some contraint or model level validation to omit possible case (lock table?) when simultaneously same value
may be saved to different Bar
instances?
Django 2.2.4