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

I'm working on v7. I'm trying to set a default image "my_image.png" for a binary field. If the user opens the form, "my_image.png" must be visible until the user changes it.

My code:

def _get_default_signature(self, cr, uid, context=None):
    import base64
    f = open('static/src/img/my_image.png')
    image = base64.encodestring(f.read())
    f.close()
    return image

_columns = {
    'signature': fields.binary('Signature'),
}

_defaults = {
    'signature': _get_default_signature,
}

I'm not able to show "my_image.png" as the default value for the field signature. Can anyone help me here, please?

아바타
취소
베스트 답변

use ir.attachement

first upload a file in attachments. goto  settings ->    Technical -> Data structure -> create record -> search with name

def _get_default_welcome_letter(self,cr,uid,context=None):

        attach_obj = self.pool.get('ir.attachment')

        attach_data_ids=attach_obj.search(cr,uid,[('name','=','welcome_template.docx')])

        attach_data = attach_obj.browse(cr,uid,attach_data_ids)

        return attach_data.datas


_columns = {

'welcome_pack1_download' : fields.binary('Welcome Letter'),

}

_defaults={

'welcome_pack1_download' : _get_default_welcome_letter 

}

아바타
취소
베스트 답변

Hi, your code is fine. If you get this


Just add widget=image in xml file.
<field name="signature" widget="image" />

아바타
취소
작성자

Thank you very much for your answer, Dhinesh! However, my XML was ... I tried to remove the class and the options to leave the field as you told me, but when I open the form, I still see the default picture of the camera, like the rest of the binary fields.

작성자

Sorry, but I always forget that if I write some code symbols in a comment, the line just disappears. I tried to tell you that my XML code was field name="signature" widget="image" class="oe_left oe_avatar" options="{'size': [400, 120]}"

관련 게시물 답글 화면 활동
1
12월 22
5757
2
2월 23
9260
0
7월 16
4519
1
3월 16
2002
2
8월 25
7433