model.py
from django.core.exceptions import ValidationError
def surname_validate(value):
if value == "123":
raise ValidationError('is not an even number')
class Member(models.Model):
surname=models.CharField(max_length=50,validators=[surname_validate])
other_names=models.CharField(max_length=150,null=True, blank=True)
forms.py
class MemberEditForm(forms.ModelForm):
class Meta:
model=Member
When i try to save the form with no inputs, i get the default 'this field is required' error so I know my views are correct. The thing is that my validation for surname field does not work at all and i dont understand. What am I doing wrong here. Why wont it work ??? This is frustrating