콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
12566 화면

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

아바타
취소
베스트 답변

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

아바타
취소