Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
10723 มุมมอง

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!

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
มิ.ย. 25
8210
1
มี.ค. 15
5052
Best product image size and resolution? แก้ไขแล้ว
1
ก.ค. 25
1943
1
พ.ค. 20
3359
0
มี.ค. 20
3317