user1597002
user1597002

Reputation:

dynamically set field default value

I'm doing following:

def default_get(self, cr, uid, fields, context=None):
    data = super(extended_projects, self).default_get(cr, uid, fields, context=context)
    data['test_field'] = context.get('test_field','default_value')
    return data

This works and sets the default values.

But I need to set it dynamically, specifically in the fields_view_get method (which I'm overriding as well).

if I do this (in fields_view_get):

context['test_field'] = 'new_default_value'
test_data = self.default_get(cr, uid, ['test_field'], context=context)

The new default value doesn't show for the field.

Upvotes: 0

Views: 4393

Answers (1)

OmaL
OmaL

Reputation: 5044

if you want to load data to a field from other than default_get function or _defaults dictionary, then in the context add a key called default_your_field and its value. for example context['default_test_field'] ='new_default_data'. then pass this context

Upvotes: 4

Related Questions