跳至内容
菜单
此问题已终结
2 回复
4163 查看

@http.route('/tour/<model("tour.tour"):tour>/add-exist-passenger', type='http', auth='public', website=True)

def exist_passenger(self, tour, **kw):

passenger_id = int(kw.get('passenger_id', False))

passenger = http.request.env['tour.passenger'].search([('id', '=', passenger_id)])

tour.write({'passenger_ids': [(0, 0, passenger)]}) 

return http.request.redirect('/tour/')

From above this codes, i have tour.passenger_ids as Many2many field and i need to link new passenger called passenger from my total record. when i write to tour.passenger_ids it say me the error

'tour.passenger' object has no attribute 'pop'
形象
丢弃
最佳答案

Hello Prabakaran,
I think you're trying to add a existing passenger to model "tour.tour". but your codes telling creating new passenger in model "tour.tour" like [(0, 0, passenger)] and also passenger is an recordset but  it should be a dict of values. Here is my suggestion

@http.route('/tour/<model("tour.tour"):tour>/add-exist-passenger', type='http', auth='public', website=True)
def exist_passenger(self, tour, **kw):
    passenger_id = int(kw.get('passenger_id', False))
    tour.write({'passenger_ids': [(4, passenger_id)]}) 
    return http.request.redirect('/tour/')
形象
丢弃
编写者

Great! it works...

最佳答案

Hi,

The issue is that here the passenger is not a dict, you have pass a dict of a values here,

 tour.write({'passenger_ids': [(0, 0, passenger)]}) 

uptd:

Thanks

形象
丢弃
相关帖文 回复 查看 活动
1
5月 24
5888
1
2月 23
12120
1
3月 22
3741
2
3月 21
4080
2
12月 16
6940