我在OpenERP PostgreSQL中有一个表,包含以下列:name
和description
。
我为唯一名称添加了以下验证:
_sql_constraints = [('unique_name', 'unique(name)', 'A record with the same name already exists.')]
它工作正常,但区分大小写。目前,它接受“米奇”、“米奇”和“米奇”等价值观:
Wrong Way:
--------------------------
| name | description |
--------------------------
| mickey | not a mouse |
--------------------------
| MICKEY | not a mouse |
--------------------------
| Mickey | not a mouse |
--------------------------
是否有方法修改验证代码,使其不允许用户添加多个值,如“Mickey”、“Mickey”和“Mickey”?如何使唯一密钥验证不区分大小写?
Right Way:
--------------------------------
| name | description |
--------------------------------
| mickey | not a mouse |
--------------------------------
| mickey mouse | is a mouse |
--------------------------------
| donald | is a duck |
--------------------------------
以更简单的方式在Odoo 8.0或更高版本中使用约束。 获取模型的所有记录,并使用lower()检查所需的字段值,不包括自记录。
对于
case insensitive constraints
签出HERE 否则,您可以始终使用Openerp Constraints而不是SQL。对于openerp约束
看看这个例子
这样就不会从数据库中读取所有数据:
相关问题 更多 >
编程相关推荐