(Django) Trim whitespaces from charField
- by zardon
How do I strip whitespaces (trim) from the end of a charField in Django?
Here is my Model, as you can see I've tried putting in clean methods but these never get run.
I've also tried doing name.strip(), models.charField().strip() but these do not work either.
Is there a way to force the charField to trim automatically for me?
Thanks.
class Employee(models.Model):
"""(Workers, Staff, etc)"""
name = models.CharField(blank=True, null=True, max_length=100)
# This never gets run
def clean_variable(self):
data = self.cleaned_data['variable'].strip()
return data
def __unicode__(self):
return self.name
class Meta:
verbose_name_plural = 'Employees'
# This never gets run either
class EmployeesForm(forms.ModelForm):
class Meta:
model = Employee
def clean_description(self):
#if not self.cleaned_data['description'].strip():
# raise forms.ValidationError('Your error message here')
self.cleaned_data['name'].strip()