Odoo Help

Welcome!

This community 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.

1

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

By
oumaima
on 5/13/13, 3:13 PM 5,445 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)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

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

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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