For next two models:

```py
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:

```py
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**