跳至内容
菜单
此问题已终结
4 回复
35044 查看

Is there a way to limit number of digits in integer in OpenERP like you can in char type? I need field that would only let you enter max two digits.

For example with char, you can do this:

'char_field': fields.char(size=2),

Then if you try to enter more than two symbols, it won't write it.

But if I create integer field:

'integer_field': fields.integer(),

It will let me write any number of digits I want.

形象
丢弃
编写者

Thanks Atul It's an easy solution..

最佳答案

You can use a _constraint to check the value of your integer and raise an exception if it is not in your desired range.

Check this blog post about how to create a constraint.

形象
丢弃
最佳答案

The size attribute is also availbe for integer fields!

'integer_field': fields.integer('My Integer', size=4),

 

Regards.

形象
丢弃

It seems not working like Char field. Because when we use 'size' in fields.Char it won't allow more than that limit. But in Integer it allow to enter more than this limit.

So better user constraint for that specific field.

相关帖文 回复 查看 活动
6
3月 24
21482
1
3月 23
2295
0
11月 16
2455
1
5月 18
6035
0
12月 24
951