I have a Model and ModelForm with custom validator (which only allows "H" or "A" in the CharField):
def home_away_valid(value):
return value == 'H' or value == 'A'
class Team(models.Model):
name = models.CharField(max_length=180)
home = models.CharField(max_length=2, validators=[home_away_valid], default='H', db_index=True)
class TeamForm(ModelForm):
class Meta:
model = Team
fields = ['home', 'name']
However when I run full_clean() with another value (not H or A) it doesn't not raise a validation exception:
try:
team = TeamForm({
'name': 'Test Team',
'home': 'S'
})
team.full_clean()
new_team = team.save()
print(new_team.id)
except ValidationError as e:
print(e)
Why does this not raise an Exception? (I have tried doing the full_clean() on both the ModelForm and Model, neither raises an Exception)