为了提高此功能的速度,我们可以使用SQL查询而不是Python ORM方法。我有很多产品来保存product_template
,同时在表格中添加图片时出现错误。之后我在ir_attchment
表中识别出图像保存。保存的图像无法进入视图。
product_obj("insert into
ir_attachment(name,res_name,res_model,res_field,res_id,type)
values(%s,%s,%s,%s,%s,%s)",
[image_medium,name,'product.template','image_medium',res[0],'binary'])
当然,在视图中无法看到。二进制数据不再保存在数据库中。这就是您的查询快捷方式不起作用的原因。
Odoo中的一些Binary
字段将参数attachment
设置为True
,这意味着该字段的二进制数据将被保存到具有一些特殊配置的附件(ir.attachment
)中。 Odoo使用字段res_field
以及res_id
和res_model
以便稍后找到这样的附件,同时加载数据,例如表单视图,因为您的查询已经设置。
所以我的猜测是,Odoo没有在数据库中查找二进制数据。