2013-03-15 59 views
0

我想創建一個簡單的函數來返回active_ids中的連接列表。不過,我不斷收到此錯誤:openerp:簡單的功能

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

代碼如下:

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 
} 

我猜我無法理解的是函數的返回類型。當我查看現有代碼時,有時會看到返回的數組([]),有時{},有時候我會認爲它是單個值res [0] [0]。

請協助。

由於

EDIT:工作的代碼:

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

該錯誤信息顯示context.get是一種方法,而不是一個字典。因此,下面的

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

應該讀

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

謝謝。這確實是我的疏忽。 – 2013-03-15 09:11:44