Community mailing list archives

community@mail.odoo.com

Re: how to set a unique default value for new fields

by
Pedro M. Baeza
- 03/23/2016 21:01:54
This is because at the end, you're passing a static string to the lambda expression. You need to have a dynamic method that is called each time the default is called:

def _default_token(self):
    return uuid.uuid4().hex

token = fields.Char(default=_default_token)

Regards.

2016-03-24 0:32 GMT+01:00 pedro cachaca <pcachaca33@gmail.com>:
Hello,

I want to add following new field to a model :

token = fields.Char(default=lambda self: '%s' % uuid.uuid4().hex )

But when I update the module, all existing records get the same value uuid for token...

The lambda function is executed one time and result applied to all the records !

How to make the function executed once updating each records ?

Thanks.

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe