【发布时间】:2018-01-17 22:29:25
【问题描述】:
我想将图像字段添加到自定义模型中,其中图像是从给定的产品 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"/>
但没有显示任何内容,尽管测试的 product_id 有图像。
这是调试输出:
$ odoo -c /etc/odoo/odoo.conf -d testdatabase
debug -compute-product-image
64.78 Kb
<type 'str'>
debug -compute-product-image end
【问题讨论】: