Skip to Content
Menu
This question has been flagged
3 Replies
11107 Views

In my module I have a binary field and I show that field using the image widget, but when that field has no value, it shows a blank space in the user interface. I would like to know how to set a default image to that field, so when the user has not set a value for the image field the interface would show a default image instead. I am working with odoo 12

Avatar
Discard
Best Answer

Hi,
You can try this method,
add a default image in this location "static/src/img"

image = fields.Binary("Photo", default='_get_default_image')

define _get_default_image():

def _get_default_image(self):
image_path = modules.get_module_resource('your_module_name', 'static/src/img', 'default.png')
return tools.image_resize_image_big(base64.b64encode(open(image_path, 'rb').read()))

Regards

Avatar
Discard