Odoo Help

0

How to traverse a field value of another model in kanban view?

By
manuthalasseril
on 10/4/15, 4:33 AM 1,348 views

Hi friends, I have two models called Gallery and GalleryLine

class Gallery(models.Model):
_name = 'website.gallery'
name = fields.Char(string="Album Name", required=True)
media_lines = fields.One2many('website.gallery.line.medias', 'gallery_id', string="Media Lines")
class GalleryLine(models.Model): 
_name = 'website.gallery.line'
def get_default_image(self):
image_path = get_module_resource('website_gallery', 'static/src/images', 'default_image.png')
return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64'))
@api.depends('image')
def _compute_thumbnail_image(self):
size = (300, 225)
for record in self:
self.thumbnail_image = tools.image_resize_image(self.image, size)
name = fields.Char(string="Media Name", required=True)
media_type = fields.Selection(selection=[
('image', 'Image'),
('video', 'Youtube Video'),
], string="Media Type", default='image', required=True)
image = fields.Binary(string="Image", default=get_default_image)
thumbnail_image = fields.Binary(string="Thumbnail Image", compute='_compute_thumbnail_image')
video = fields.Text(string="Video", translate=False)
gallery_id = fields.Many2one(comodel_name='website.gallery', delegate=True, required=True, string="Album Name")

And I created a kanban view which was given below  

<record model="ir.ui.view" id="view_gallery_albums_kanban">
<field name="name">gallery.albums.kanban</field>
<field name="model">website.gallery</field>
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban class="oe_background_grey">
<field name="name" />
<field name="description" />
<field name="sequence" />
<field name="media_lines" />
<templates>
<t t-name="kanban-box">
<a name="%(website_gallery.view_gallery_media)d" type="action"
class="oe_sparkline_bar_link">
<div class="oe_kanban_card oe_kanban_global_click">
<div class="oe_kanban_content">
<h4 class="text-center" name="name">
<strong>
<field name="name" />
</strong>
</h4>
<div class="oe_clear"></div>
<!-- -->
<div class="oe_kanban_gallery_avatars">
<t t-foreach="record.media_lines.raw_value.slice(0,3)"
t-as="image">
<img t-if="record.media_lines.media_type.raw_value=='image'"
t-att-src="kanban_image('website.gallery.line.medias', 'image', image)"
t-att-data-member_id="image" />
<t t-if="record.media_lines.media_type.raw_value=='video'">
<!-- Something other -->
</t>
</t>
</div>
<!-- -->
<div class="oe_clear"></div>
<div class="oe_center oe_gallery_description text-center"
name="description">
<field name="description" />
</div>
</div>
</div>
</a>
</t>
</templates>
</kanban>
</field>
</record>

I have problem exactly on this line

<t t-foreach="record.media_lines.raw_value.slice(0,3)"
t-as="image">
<img t-if="record.media_lines.media_type.raw_value=='image'"
t-att-src="kanban_image('website.gallery.line.medias', 'image', image)"
t-att-data-member_id="image" />
<t t-if="record.media_lines.media_type.raw_value=='video'">
<!-- Something other -->
</t>
</t>

I will getting this error:

Error: QWeb2 - template['kanban-box']: Runtime Error: TypeError: dict.record.media_lines.media_type is undefined

How can we achieve to take the field value of another model in kanban view? Thanks in advance..







1

Axel Mendoza

--Axel Mendoza--
12091
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 10/5/15, 2:45 AM

If you are iterating on record.media_lines and using every result as the image variable on every iteration of the loop you need to use image.medi_type in your expressions inside the loop

No its not working on kanban view...

manuthalasseril
on 10/10/15, 6:02 AM

No its not working on kanban view...

manuthalasseril
on 10/10/15, 6:02 AM

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.

Register

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)

Stats

Asked: 10/4/15, 4:33 AM
Seen: 1348 times
Last updated: 10/5/15, 2:45 AM