如何解决IndexError: tuple index out of range 奥多14
File "/usr/lib/python3/dist-packages/odoo/http.py",line 315,in _handle_exception
raise exception.with_traceback(None) from new_cause
IndexError: tuple index out of range
打印 vals['partner_ids'] 时,我得到: [(4,3)] 这是我的代码,请问有什么问题?
class CalendarEvent(models.Model):
_inherit = 'calendar.event'
present_ids = fields.Many2many('res.partner','calendar_event_present_ids','calendar_id','present_id',string='Presents')
minutes = fields.Html(string='Minutes')
@api.model
def create(self,vals):
if vals.get('partner_ids',False):
_logger.info("%s",vals['partner_ids'])
vals.update({'present_ids': [(6,vals.get('partner_ids')[0][2])]})
return super(CalendarEvent,self).create(vals)
解决方法
试试这个:
list_data = vals.get('partner_ids')[0][2]
blank_list = [ls for ls in list_data] # you'll get the list
或者你可以使用循环来创建列表
blank_list = []
for l in list_data:
blank_list.append(l)
# then use [(6,_,ids)]
vals.update({'present_ids': [(6,blank_list)]})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。