gpt4 book ai didi

python - 如何用值 [ODOO 12] 更新 One2many 列表

转载 作者:太空宇宙 更新时间:2023-11-04 04:07:42 24 4
gpt4 key购买 nike

我添加了一种方法,在类(class)中对老师进行研究,然后他在院子里添加(类(class)有几节课,每节课只有一位老师)我的问题是当我点击按钮时它没有更新表格,他在每次点击下面添加了另一行

这是我的代码

    teacher_ids = fields.One2many('school.teacher', 'course_id', string='Teacher')

def get_teachers (self):
lesson = self.env['school.lesson'].search([])

teacher_list = []
for rec in lesson:
if rec.course_id.id == self.id:
print(rec.teacher_id.name)

teacher_list.append([0,0,{
'teacher_name': rec.teacher_id.id,
'lesson_id': rec.id,
}])
print('teacher_list',teacher_list)
self.write({'teacher_ids' : teacher_list})
return

我发现

(6, 0, [IDs])          replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

但我不知道如何在我的方法中使用

最佳答案

先放

self.teacher_ids = [(6, 0, [])]

然后用

更新
self.write({'teacher_ids' : teacher_list})

它会起作用:

def get_teachers (self):
lesson = self.env['gestcal.lesson'].search([])

teacher_list = []
for rec in self.lesson_id:
teacher_list.append([0,0,{
'teacher_name': rec.teacher_id.id,
}])
print('teacher_list',teacher_list)
self.teacher_ids = [(6, 0, [])]
self.write({'teacher_ids' : teacher_list})
return

关于python - 如何用值 [ODOO 12] 更新 One2many 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56943475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com