Hello everyone,
I am trying to add dynamically image to my website. Im on v.15.0 could you please advise ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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:
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"
In the above code, record._name refers to the model name and record.id refers to the ID of the record.
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)
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 3 15
|
7840 | ||
|
4
thg 5 25
|
3170 | ||
|
2
thg 1 25
|
2143 | ||
|
4
thg 1 25
|
4244 | ||
|
0
thg 11 24
|
1547 |