Doubt in odoo to make unique a field without using sql sentence

0

The issue is that some time ago I did a odoo test, in which I was asked to have a field in a table

I know that with sql it would be something like that

_sql_constraints = [('def_identification_unique', 'unique(blablabla)', 
'blablabla must be unique!')]

I would like to know how to make the field unique but using a python function.

Thanks

    
asked by Sheparddilla 20.02.2018 в 22:28
source

1 answer

0

To make a single field, we add the constraint in the definition of the model with Python, when we are going to create the table or when we create the field (we could not add it to a field with previous data.

_sql_constraints = [
        ('nombre_constraint', 'unique(nombre_campo)', "Mensaje a mostra en caso de violación"),
    ]

There is an open thread on the subject at: link

    
answered by 21.02.2018 в 09:17