ODOO 用户默认头像-怎么设置的默认头像

mac2024-05-19  36

在模型中

from odoo.modules.module import get_module_resource class HrEmployeePrivate(models.Model): _name = "hr.employee" ... ... image_1920 = fields.Image(default=_default_image) @api.model def _default_image(self): image_path = get_module_resource('hr', 'static/src/img', 'default_image.png') return base64.b64encode(open(image_path, 'rb').read())

可以看到,在设置默认值的时候,使用了一个 get_module_resource 方法,在使用前先引用进来

image_path = get_module_resource('hr', 'static/src/img', 'default_image.png')

指定了在 hr 模块下的 static/src/img 文件夹下的 default_image.png 

之后使用base64.b64encode(open(image_path, 'rb').read()) 转化为二进制存储。

最新回复(0)