python - 如何打印动态sql约束错误语句
问题描述
我正在使用 odoo 11,我想更改以下 SQL 约束的错误状态并打印一条动态错误语句,该语句在错误消息中显示字段“数字”。
from odoo import api, fields, models
class ValidateMessageUnique(models.Model):
_inherit = 'account.invoice'
_sql_constraints = [
('number_uniq', 'unique(number, company_id, journal_id, type)', 'Invoice Number should be unique per Company!' )
]
我希望 ErrorMessage 是'Invoice Number'+number+ 'should be the unique per company'
.
解决方案
不,无法在_sql_constraint
错误消息中打印动态消息。
您必须知道,您在其中写的任何消息_sql_constraint
都不是可编辑的字母。
如果您希望该消息动态,则有一种方法,那么您需要检查发生此类错误时的所有可能性,然后需要使用动态消息内容发出警告。希望你能好好理解。
推荐阅读
- c - 有没有办法在 C 中获取数字作为字符并验证它们?
- python - 如何在 Python 中编写参数函数 r=e ^cos(θ) −2cos(4θ)+sin ^5 ( θ/12)?
- r - R:注释多行
- javascript - 如何从 xpath 中获取值
- highcharts - Highcharts:yAxis.height 不缩放可绘制区域,导致图表脱离图表
- javascript - 如何使用 javascript 从公开可用的 Google 表格中读取一列或一行
- node.js - “对象”类型上不存在属性“json”。ts(2339)
- android - 已超出每日保存配额
- r - 如何使用 nwk 格式的树在 ggtree 中斜体化物种名称?
- r - 切换选项卡时保存 selectInput 的反应值