跳至内容
菜单
此问题已终结
2 回复
10690 查看

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 !

形象
丢弃
编写者 最佳答案

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 ! 

形象
丢弃
最佳答案

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!

形象
丢弃
相关帖文 回复 查看 活动
2
6月 25
8179
1
3月 15
5025
1
7月 25
1917
1
5月 20
3325
0
3月 20
3303