Из Django Docs :
Model.clean()
""" This method should be used to provide custom model validation, and to
modify attributes on your model if desired. For instance, you could use it to
automatically provide a value for a field, or to do validation that requires
access to more than a single field: """
def clean(self):
from django.core.exceptions import ValidationError
if self.status == 'draft' and self.pub_date is not None:
raise ValidationError('Draft entries may not have a publication date.')
Поэтому для ваших целей вы должны написать что-то вроде следующего для вашей similarity
модели:
def clean(self):
from django.core.exceptions import ValidationError
if self.id1 == self.id2:
raise ValidationError('Entries must compare different objects')