This question has been flagged
1 Reply
18139 Views

Hi,

How to upload an image as an attachment inside the form like the way we add a field.


Regards

Avatar
Discard
Best Answer

Hi,

You can add the attachment by using a binary field.

Eg 1:

Python

company_favicon = fields.Binary("Favicon", attachment=True,
help="This field holds the image used for as favicon")

Xml 

<field name="company_favicon"
widget="image"
class="oe_avatar"
options="{'preview_image': 'image_small', 'size': [30, 30]}"/>

Eg 2: (You can add Multiple attachments and download)

Python

image = fields.Many2many('ir.attachment', string="Image")

Xml

<field name="image" widget="many2many_binary"/>

Thank you.


Avatar
Discard
Author

Thanks but i can't download it again, any solution ?

Hai medmars,

I just update my answer. check it. I think it will help you.

Thank you

Author

Thanks So much Avinash it work perferctly.

Author

Hi,

It's me again :)

following the 2nd Eg, i added two attachment fields in my form, but when i fill out just one field the other attachment field take the same picture. So i can't add different attachements in this two fields

Any suggestion.( i want to fill the 1st attachment by an ID card and the second by a picture)

Thanks

I Try this code, but when i click save button it doesn't show image