Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
13242 Zobrazení

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?

Avatar
Zrušit

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

Nejlepší odpověď

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

Avatar
Zrušit

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

Nejlepší odpověď

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:

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
zář 19
4936
2
úno 24
2953
1
srp 23
4678
6
dub 23
16907
2
pro 22
6142