This question has been flagged
3 Replies
4507 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:

https://github.com/OdooCommunityWidgets/website_multi_image

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:

data-src

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;}"/>
</t>

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'),
}

product_image()
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),
}

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

product_template()

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.

Avatar
Discard

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

Author

@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.

Best Answer

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

Avatar
Discard