This question has been flagged
3 Replies
24715 Views

I am trying to add a slideshow to the product.template form view. In this, I want to show all images related to a product as a slideshow on the backend.

I have managed to create the product.image class and created the one2many relationship successfully as follows.


class product_product(osv.Model): _inherit = "product.template" _columns = { 'images': fields.one2many( 'product.images', 'product_id', 'Product Images' ) }

I however have a problem displaying the list of images using a <t-foreach tag. Here is the part of the view that I am adding to the product.product_template_form_view view.

 <div class="slider project-slider slider-for">
<t t-foreach="record.images" t-as="i"> 
<div><span t-field="i.image" class="img-responsive" t-field-options="{"widget": "image", "class": "img-responsive"}"/></div>
</t>
</div>

I suppose the line <t t-foreach="record.images" ...... is not fetching the current product object. How to I make it to iterate through the "images" field of the current record?

Here is the full xml file

        <record id="view_product_form_img" model="ir.ui.view">
<field name="name">product.product.images</field>
<field name="model">product.template</field>
<field name="priority">3</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<page string="Sales" position="after">
<!--<page string="Product Slider">
<field name="images" nolabel="1"/>
</page> -->
<!-- a copy of website_multi_image/product_images.xml-->
<page string="Product Images">
<field name="images" mode="kanban" context="{'default_name': name}">
<kanban>
<field name="name"/>
<field name="description"/>
<field name="image_alt"/>
<field name="image"/>
<templates>
<t t-name="kanban-box">
<div style="position: relative">
<div class="oe_module_vignette">
<a type="open">
<img t-att-src="kanban_image('res.partner', 'image', record.id.value, {'preview_image': 'image_small'})" class="oe_avatar oe_kanban_avatar_smallbox"/>
</a>
<div class="oe_module_desc">
<div class="oe_kanban_box_content oe_kanban_color_bglight oe_kanban_color_border">
<table class="oe_kanban_table">
<tr>
<td class="oe_kanban_title1" align="left" valign="middle">
<h4><a type="open"><field name="name"/></a></h4>
<i><div t-if="record.description.raw_value">
<field name="description"/></div></i>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
<!-- a copy of website_multi_image/website_product_image_carousel.xml to display the slider-->
<div class="container-fluid">
<style>
.slider-for {
min-height:50px;
background-color:grey;
}
.slider-nav {
min-height:20px;
}
</style>
<div class="row-fluid">
<p class="oe_grey">
<strong>Note:</strong> display the slideshow here now.
</p>
<div class="slider slider-for">
<t t-foreach="product.images" t-as="i">
<h2 t-esc="i.name"/>
<div><span t-field="i.image" class="img-responsive" t-field-options="{"widget": "image", "class": "img-responsive"}"/></div>
</t>
</div>
</div>
<div class="row-fluid">
<div class="slider slider-nav">
<t t-foreach="product.images" t-as="i">
<h2 t-esc="i.name"/>
<div><span t-field="i.image" class="img-responsive" t-field-options="{"widget": "image", "class": "img-responsive"}"/></div>
</t>
</div>
</div>
</div>
</page>
</page>
</field>
</record>

I realised the qweb tags is not being processed


Avatar
Discard
Author

Hi Luke, thats the project I am using. I have edited the question to include my xml file in full. I realised the qweb tags in the view are not being processed.