Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
13488 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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:

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 19
5114
2
thg 2 24
3257
1
thg 8 23
4865
6
thg 4 23
17101
2
thg 12 22
6307