MinLengthValidator error min and max value Follow
Newbie - I'm trying to call clean_title_length to error on length title is less than 3 characters or more than 25 characters.
I tried using MinLengthValidator, but it did not work.
class Video(models.Model):
title = models.CharField(max_length=255)
url = models.URLField()
youtube_id = models.CharField(max_length=255)
def clean_title_length(self):
data = self.cleaned_data['title']
length= len(data)
if length < 3 or length > 25:
raise ValidationError("The length of the title must be between 3 and 25 characters")
else:
return data
views.py
def add_video(request):
form = VideoForm()
if request.method == 'POST':
filled_form = VideoForm(request.POST)
if filled_form.is_valid():
Form always come back valid.
Could you give me a snippet that would show error message above the text box saying title between 3 and 25 characters?
TIA.
Please sign in to leave a comment.