我想在自定义模型中添加一个图像字段,其中图像是从给定的产品id动态检索的
product_image = fields.Binary("Product Image", compute='_compute_product_image')
def _compute_product_image(self):
print 'debug -compute-product-image'
image = False
if self.product_id:
product_image = self.env['product.template'].search([('id', '=', self.product_id.id)]).image
print product_image
print type(product_image)
print 'debug -compute-product-image end'
return product_image
稍后在视图中:
<field name="product_image" widget="image" class="oe_avatar" readonly="True"/>
但是什么也不显示,尽管测试的产品id有一个图像。
这是调试输出:
$ odoo -c /etc/odoo/odoo.conf -d testdatabase
debug -compute-product-image
64.78 Kb
<type 'str'>
debug -compute-product-image end
将映像类型str更改为base64
convertToBase64 (binaryString) {
this.base64textString= btoa(binaryString);
console.log(btoa(binaryString));
}