Say I have a bunch of tables where the objects are marked deleted rather than actually deleted. Now, I want to enforce a constraint that there can be only one non-deleted object with a particular set of field values, but I can have multiple deleted objects with the same field values.
class Deletable(models.Model):
deleted = models.BooleanField(default=False)
class Meta:
abstract=True
def soft_delete(self):
self.deleted=True
self.save()
class ConcreteModel(Deletable):
a = models.IntegerField()
b = models.IntegerField()
class Meta:
#wrong because there may have been some deleted rows
unique_together=('a', 'b')
What is the best way to enforce the constraint?