This question has been flagged
1 Reply
5939 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..







Avatar
Discard
Best Answer

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

Avatar
Discard
Author

No its not working on kanban view...

Author

No its not working on kanban view...