0
votes

I'm trying to create a simple function to return a concatenated list of Ids in active_ids. But I keep getting this error:

TypeError: 'builtin_function_or_method' object has no attribute '__getitem__' 

Code is as follows:

def _test(self, cr, uid, context=None):
    if context is None:
        return False
    result = 'Sel: '
    for id in context.get['active_ids']:
        result = result + '[' + id + ']'
    return result

_columns = {
    'test': fields.text('Test')
}

_defaults = {
    'test': _test
}

I guess what I am unable to understand is the return types in functions. When I look at existing code, sometimes I see arrays ([]) being returned, sometimes {} and at times things like res[0][0] which I assume to be single values.

Please assist.

Thanks

EDIT: working code:

def _test(self, cr, uid, context=None):
    if context is None:
        return False
    result = 'Sel: '
    if context.get('active_ids'):
        for id in context.get('active_ids'):
            result = result + '[' + str(id) + ']'
    return result
1

1 Answers

1
votes

The error message suggests context.get is a method, not a dictionary. Thus, the following

for id in context.get['active_ids']:

should read

for id in context.get('active_ids'):