Many questions already on this topic, but not what i'm searching for.
I have this Model:
class Options(TimeStampedModel) option_1 = models.CharField(max_length=64) option_2 = models.CharField(max_length=64) class Meta: unique_together = ('option_1', 'option_2') Now I have a unique constraint on the fields. Is there a way to also define this the other way around so that it doesn't matter what was option_1 and what was option_2
As example:
Options.create('spam', 'eggs') # Allowed Options.create('spam', 'eggs') # Not allowed Options.create('eggs', 'spam') # Is allowed but should not be Thanks in advance!
CheckConstraint? I'd like to push more validation into the database itself, but using aManyToManyrelationship as in @etene's solution below is not an option. The problem I'm finding withCheckConstraint's is they seem to be limited to the data in the row being inserted.