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 make field become unique / primary key

By
heru
on 12/16/14, 5:27 PM 1,220 views

Hi, i want to question ...

I create field, but i want the field become unique or primary key , 

class Product (osv.osv):
    _name = 'kode.warna'
    _columns = {
                'name': fields.char('Kode Warna', required=True),
                'ket': fields.char('Nama Warna', required=True),
                }
    

How field 'name' become unique or primary key ?

 

thanks ...

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 12/16/14, 5:39 PM

Additionally define something like:

 _sql_constraints = [ ('name_uniq', 'unique(name)', 'Two foos with the same name!') ]

or like

    _sql_constraints = [
        ('name_uniq', 'unique(name, company_id)', 'Name must be unique per Company!'),
    ]

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/16/14, 5:27 PM
Seen: 1220 times
Last updated: 3/16/15, 8:10 AM