python - Parse value to None in ndb custom property -
i have custom ndb property subclass should parse empty string none. when return none in _validate function, none value ignored , empty string still used.
can somehow cast input values none?
class booleanproperty(ndb.booleanproperty): def _validate(self, value): v = unicode(value).lower() # '' should casted none somehow. if v == '': return none if v in ['1', 't', 'true', 'y', 'yes']: return true if v in ['0', 'f', 'false', 'n', 'no']: return false raise typeerror('unable parse value %r boolean value.' % value)
maybe looking ndb.computedproperty?
class yourbool(ndb.model): my_input = stringproperty() val = ndb.computedproperty( lambda self: true if self.my_input in ["1","t","true","y","yes"] else false)
Comments
Post a Comment