Community mailing list archives

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

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)


2016-03-24 0:32 GMT+01:00 pedro cachaca <>:

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 ?


Post to: