Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
4 Відповіді
13324 Переглядів

Here's my model.py:

def ExampleForm(models.Model):
    _name = 'example.form'
    
    name = fields.Char('Name')
    picture = fields.Binary('Picture', attachment=True)

And here's my data.xml

<record model="example.form" id="example_form">
  <field name="name">Hello World</field>
  <field name="picture">
    <!-- Assume that my image is located in /example/data/helloworld.png -->
  </field>
</record>

What options do I use for the picture/binary field?

Аватар
Відмінити

I figured it out, it was "my_module/static/img/my_logo.png"

Найкраща відповідь

Hi Mc,

You can simply set the type to base64, the Odoo framework will handle it as base64 then. This means the image is stored as a base64 in the database and shown as an image in the Odoo frontend:

<field name="image" type="base64" file="/example/data/helloworld.png"/>

Regards,
Yenthe

Аватар
Відмінити

How would it work if I wanted to provide a relative path inside my module? I tried "./static/img/my_logo.png" but it wasn't found

Найкраща відповідь

You can simply set the type to base64, the Odoo framework will handle it as base64 then. This means the image is stored as a base64 in the database and shown as an image in the Odoo frontend:

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
вер. 19
5014
2
лют. 24
3073
1
серп. 23
4766
ir.values in odoo 11 Вирішено
6
квіт. 23
17008
2
груд. 22
6220