我最近一直在尝试使用约束
考虑以下字段
'mdt': fields.datetime('Date',required=True),
并有约束
_constraints = [
(_check_from_date, 'You can not choose future date :' + '['mdt']'),
]
这将显示约束错误消息,如下所示
Field(s) `mdt` failed against a constraint: You can not choose future date...!
我想将字段的字符串部分与错误消息连接起来,以便它显示为
Field(s) `mdt` failed against a constraint: "DATE" : You can not choose future date...!
答案 0 :(得分:0)
为你的约束创建一个函数:
_constraints = [(_check_from_date, _construct_constraint_msg, ['mdt'])]
def _construct_constraint_msg(self, cr, uid, ids, context=None):
for object in self.browse(cr, uid, ids,context=context):
return _("%s : You can not choose future date...!") % object.mdt
你也可以使用api 8来做约束。