Odoo Help


[8.0/Master] How can I call the url/src value for an image created by an image widget into a custom attribute - eg. data-src?

Luke Branch
on 12/8/14, 4:47 AM 1,909 views

I've begun work on creating a module to provide multiple product images that can be displayed on the website's product view page here:


currently the 8.0 branch I am pushing stable merges to, however the project is still very much in it's early stages of development. The module is working great for storing and displaying multiple product images onto the product page in a synced slider setup using one2many and a slider called OwlCarousel2.

What I am trying to figure out is how to call the src value from the image widget into another attribute called:


to allow for lazyloading of product images and a few other useful features. 

The code I am trying to place this img src inside of is here (t-att-data-src):

<t t-foreach="product.images" t-as="i">
<span t-field="i.image" class="item" t-field-options="{&quot;widget&quot;: &quot;image&quot;, &quot;class&quot;: &quot;owl-lazy product_detail_img&quot;, &quot;alt&quot;: &quot;i.image_alt&quot;, &quot;t-att-data-src&quot;: &quot;widget.src&quot;}"/>

here's the python in product_images.py:

from openerp.osv import osv, fields
class product_image(osv.Model):
_name = 'product.image'
_columns = {
'name': fields.char('Name'),
'description': fields.text('Description'),
'image_alt': fields.text('Image Label'),
'image': fields.binary('Image'),
'image_small': fields.binary('Small Image'),
'product_tmpl_id': fields.many2one('product.template', 'Product'),

class product_product(osv.Model):
_inherit = 'product.product'
_columns = {
'images': fields.related('product_tmpl_id', 'images', type="one2many", relation="product.image", string='Images', store=False),

class product_template(osv.Model):
_inherit = 'product.template'
_columns = {
'images': fields.one2many('product.image', 'product_tmpl_id', string='Images'),


Does anyone have any suggestions on how I can add the data-src attribute correctly to the:

<span t-field="i.image" class="item" t-field-options="{&quot;widget&quot;: &quot;image&quot;, &quot;class&quot;: &quot;owl-lazy product_detail_img&quot;, &quot;alt&quot;: &quot;i.image_alt&quot;, &quot;t-att-data-src&quot;: &quot;widget.src&quot;}"/>

in order to be able to pull the img src into the resulting img tag that is output from the image widget? I have been searching the forums, Odoo github source code and google, but I cannot figure this one out.

Ah, good post. I'm struggling with the same problem. Would like to know the answer.

21south, Ludo - 21South
on 12/9/14, 2:49 AM

@Ludo - Neobis, I'll be trying to crack this over the weekend. I'll post back here once I figure it out. Please do likewise if you find a way to do this.

Luke Branch
on 12/11/14, 5:03 AM
Dr Obx
On 3/21/15, 1:29 PM

It's a long time since then, so have you found any solution ?

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 12/8/14, 4:47 AM
Seen: 1909 times
Last updated: 3/21/15, 1:29 PM