This question has been flagged
2 Replies
8701 Views

Hello everyone !

First the code :

 

class myClass(models.Model):
    _name='myModule.myClasse'
 
    image=fields.Binary(compute='_getBase64Image')
 
 
    @api.one
    def _getBase64Image(self):
        self.image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAAC....."

The Views :

    - In the form, i use : 

<field name="image" widget="image"/>

     - In the kanban, i use :

<div class="o_kanban_image">

      <img t-att-src="kanban_image('myModule.myClass', 'image', record.id.value)"/>

</div>

So, first is my syntax ok for base64 image in a fields.Binary ? Because even if i send a base64 of a 128*128px it doesn't appear.

Then, i would like to show the "image" field in form view as original size but scaled in kanban view to fit in the kanban. Does the environnement manage this alone or i have to rework the image first ?


Actually this code doesn't work : in kanban view i have the little pictogram that shows that it can't display the image.


Thank you in advance ! :) .

Good afternoon !

Avatar
Discard
Author Best Answer

I got it !

the problem is in the fields.Binary content, i had to remove "data:image/png;base64," and it works perfectly so the correct syntax is : 

 self.image="iVBORw0KGgoAAAANSUhEUgAAAIAAAAC....."

Thank you for your time ! 

Avatar
Discard
Best Answer

you need to pass the model name as a kanban image parameter, not Module.Class.
 
Here is an example code for partner image in kanban box. here height & width will scale the image in kanban box too!

<img t-att-src="kanban_image('res.partner', 'image', record.partner_id.raw_value)" t-att-title="record.partner_id.value" width="128" height="128" class="oe_kanban_avatar pull-right"/>


Will Help!

Avatar
Discard