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()
如何我必須在聽者配置此驗證器,這樣它會接受額外的參數開始和年底?