Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to set a default for binary field?

Juan Formoso
on 2/23/15, 4:48 AM 1,881 views

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())
    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?

On 10/4/15, 12:36 PM

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 = attach_obj.browse(cr,uid,attach_data_ids)

        return attach_data.datas

_columns = {

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



'welcome_pack1_download' : _get_default_welcome_letter 



Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 2/23/15, 7:40 AM

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.

Juan Formoso
on 2/26/15, 10:11 AM

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]}"

Juan Formoso
on 2/26/15, 10:13 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 2/23/15, 4:48 AM
Seen: 1881 times
Last updated: 12/22/15, 9:22 PM