正常赋值操作:
(以某个模型对象的附件为例)
xx你的模型_model_obj.information_attachment_ids = [(6, 0, attach_ids)]
其中,attach_ids为附件对象id列表。
追加更新操作:
直接追加方式,没有找到;间接实现,每次更新前,去查询附件模型中res_model和res_id;
例如:
for dec_obj_id in xxx.xx你的模型对象_id_list: = self.env['ir.attachment'].search([('res_model', '=', 'xxx.xx你的模型名'), ('res_id', '=', dec_obj_id)]) attach_ids = [] if len(dec_attach_list_obj) > 0: for attach_obj in xx你的模型关联的附件_list_obj: attach_ids.append(attach_obj.id) xx你的模型名_model_obj = self.env['xxx.xx你的模型'].search([('id', '=', dec_obj_id)]) if len(attach_ids) > 0: xx你的模型名_model_obj.information_attachment_ids = [(6, 0, attach_ids)]