Automatically strip CharFields

1
2
3
4
5
6
7
8
9
from django import forms

def stripclean(self, value):
	if isinstance(value, basestring):
		value = value.strip()
	return oldclean(self, value)

oldclean = forms.fields.CharField.clean
forms.fields.CharField.clean = stripclean

More like this

  1. Replace slugfield validation for User username in Admin form with a CharField by dodgyville 2 years, 12 months ago
  2. Unlimited-length CharField by rfugger 1 year ago
  3. RangeField and RangeWidget by marinho 3 years, 4 months ago
  4. Custom admin widgets by field type by dgouldin 2 years, 11 months ago
  5. JSON fixtures of Intl. country codes & dial-codes by dibau_naum_h 1 year, 5 months ago

Comments

(Forgotten your password?)