StripedCharField extends django.db.models.CharField and overrides clean() to automatically strip leading and trailing whitespace character fields. Note: clean() is only called by forms, not by orm.
diff --git a/xos/core/models/plcorebase.py b/xos/core/models/plcorebase.py
index 5ca2a88..e37a2cf 100644
--- a/xos/core/models/plcorebase.py
+++ b/xos/core/models/plcorebase.py
@@ -23,6 +23,14 @@
def notify_observer(*args, **kwargs):
pass
+class StrippedCharField(models.CharField):
+ """ CharField that strips trailing and leading spaces."""
+ def clean(self, value, *args, **kwds):
+ if value is not None:
+ value = value.strip()
+ return super(StrippedCharField, self).clean(value, *args, **kwds)
+
+
# This manager will be inherited by all subclasses because
# the core model is abstract.
class PlCoreBaseDeletionManager(models.Manager):