Add option to remove leading and trailing white spaces from char

issue7914
review340511008
This commit is contained in:
Cédric Krier committed 2022-09-19 21:25:55 +02:00
1 parent c21b173743
commit 41cb19c64b
1 file changed
+10
@@ -202,6 +202,16 @@ class Field(object):
class CharField(Field):
_default = ''
def set(self, record, value):
if self.attrs.get('strip') and value:
if self.attrs['strip'] == 'leading':
value = value.lstrip()
elif self.attrs['strip'] == 'trailing':
value = value.rstrip()
else:
value = value.strip()
super().set(record, value)
def get(self, record):
return super(CharField, self).get(record) or self._default