我想创建一个在用户输入无效日期时引发错误的函数,所以如果我们在当前日期之前输入一个日期,它会显示错误,有什么想法吗?
我的班级看起来像:
class business_trip(orm.Model):
_columns = {'start_trip': fields.datetime('Trip Starts on:',translate=True, required=False),
'start_business': fields.datetime('Business Starts on:',translate=True, required=False),
'end_business': fields.datetime('Business Ends on:',translate=True, required=False),
'end_trip': fields.datetime('Trip Ends on:',translate=True, required=False),
答案 0 :(得分:1)
您可以添加添加Python约束,例如
@api.one
@api.constrains('start_trip', 'start_business', 'end_business', 'end_trip')
def _check_date(self):
now = datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT)
if self.start_trip and now < self.start_trip:
raise exceptions.ValidationError("Entered Date Should be greter then Today")
elif self.start_business and now < self.start_business:
raise exceptions.ValidationError("Entered Date Should be greter then Today")
elif self.end_business and now < self.end_business:
raise exceptions.ValidationError("Entered Date Should be greter then Today")
elif self.end_trip and now < self.end_trip:
raise exceptions.ValidationError("Entered Date Should be greter then Today")
答案 1 :(得分:1)
谢谢大家,这是我的解决方案:
<canvas ng-if="render"> </canvas>
答案 2 :(得分:0)