class Product(models.Model):
name = CharField(...)
class Image(models.Model):
src = ImageField(...)
product = ForeignKey(Product, ...)
Meta:
constraints = [
CheckConstraint(???)
]
Currently, CHECK expressions cannot contain subqueries nor refer to variables other than columns of the current row (see Section 5.4.1). The system column tableoid may be referenced, but not any other system column.Так явно не сделать у постгреса, или писать триггер, или с уникальность поиграть, как предложили.