0
我知道我可以使用安装在模型的列一个验证,根据SQLAlchemy的documenation:SQLAlchemy的验证和额外的参数
def validate_phone(target, value, oldvalue, initiator):
"Strip non-numeric characters from a phone number"
return re.sub(r'(?![0-9])', '', value)
# setup listener on UserContact.phone attribute, instructing
# it to use the return value
listen(UserContact.phone, 'set', validate_phone, retval=True)
,但我想额外的参数传递给验证器,例如:
def check_range(target, value, oldvalue, initiator, begin, end)
if value in range(begin, end):
return value
else:
raise ValidationError()
如何我必须在听者配置此验证器,这样它会接受额外的参数开始和年底?