I have a simple URLField in my model
link = models.URLField(verify_exists = False, max_length = 225)
I would like to strip the leading and trailing spaces from the field. I don't think I can do this in "clean_fieldname" or in the "clean" method.
Do I need to sub-class the "URLField" and remove the spaces in to_python method? Is there a better way to do this without any sub-classing?
Edited
This is my form
class StoryForm(forms.ModelForm):
title = forms.CharField(max_length=225, error_messages={'required' : 'Enter a title for the story'})
link = forms.URLField(max_length=225, error_messages={'required' : 'Enter a link to the story', 'invalid' : 'Enter a valid link like www.ted.com'})
class Meta:
model = models.Story
fields = ('title', 'link')
def clean_link(self):
link = self.cleaned_data['link']
return link.strip()
and my model
class Story(models.Model):
title = models.CharField(max_length = 225)
link = models.URLField(verify_exists = False, max_length = 225)