Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2239 มุมมอง

Hello everyone,

I am trying to add dynamically image to my website. Im on v.15.0 could you please advise ?


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

To add dynamic images to your website in Odoo v15.0, you can use the t-att-src attribute in QWeb templates. Here's an example of how you can achieve this:

  1. Define a field in your model that stores the image data or the path to the image file.


image = fields.Binary(string='Image')


In your QWeb template, use the t-att-src attribute to dynamically set the source of the image based on the field value.

img t-if="record.image" t-att-src="'/web/image/' + record._name + '/' + record.id + '/image'" alt="Image" 

  1. In the above code, record._name refers to the model name and record.id refers to the ID of the record.

  2. Make sure you have appropriate access rights set for the image field so that it can be accessed publicly.


_inherit = 'your.model'
_description = 'Your Model'

image = fields.Binary(string='Image', attachment=True, store=True)
image_medium = fields.Binary(string='Medium-sized image', attachment=True, store=True, compute='_compute_image_medium')

@api.depends('image')
def _compute_image_medium(self):
for record in self:
record.image_medium = tools.image_resize_image_medium(record.image)

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 15
7232
2
ม.ค. 25
1031
4
ม.ค. 25
2897
0
พ.ย. 24
598
website module is not working แก้ไขแล้ว
1
พ.ย. 24
1281