Odoo Help

1

how to make a unique field in a module [Closed]

By
oumaima
on 5/13/13, 3:13 PM 7,021 views

The Question has been closed

by
Sudhir Arya (SA)
on 06/08/2013 08:30:23

Hi,i'm trying to make a unique field in my module but it doesn't work,i tried with _sql_constraints but i still add 2 records with the same cne

myfile.py

enter code here_columns = {

'cne':fields.char('Matricule', size=64,required=True), } _constraints = [('student_name','unique(cne)', 'cne already exists')]

7
Sudhir Arya (SA)
On 5/14/13, 1:58 AM

Try _sql_constraints in new database. It will work then.

Try with

_sql_constraints = [
    ('cne_unique', 'unique(cne)', 'cne already exists!')
]

Restart your server and create new database.

thank you it work's now;i had to create a new database

oumaima
on 5/14/13, 6:44 AM
6
Sandeep
On 6/8/13, 4:30 AM

Hi Yes use constraints with your model class just the sibling of _columns and _defaults

type:

 _sql_constraints = [
('your_field_name_unique', 'unique(your_field_name)', 'Can't be duplicate value for this field!')

]

Thanks
Sandeep

ok thank you i will add the help message

oumaima
on 6/8/13, 8:22 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 5/13/13, 3:13 PM
Seen: 7021 times
Last updated: 3/16/15, 8:10 AM