This cannot be done with pure Django. There is a ticket to add restrictions CHECK: https://code.djangoproject.com/ticket/11964
, team_home == team_visitors , , . , MySQL PostgresQL:
alter table myapp_match add constraint match_teams_not_equal check (team_home_id <> team_visitors_id);
. , , .
, team_home != team_visitors save:
class Match(models.Model):
....
def save(self, *args, **kwargs):
if self.team_home == self.team_visitors:
raise Exception('attempted to create a match object where team_home == team_visitors')
super(Match, self).save(*args, **kwargs)
- update queryset Django, Match , team_home == team_visitor.