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

In my custom module there is a binary field for images. I loaded an image in that. I have another HTML field for image preview.  My preview field image need to change when I add css styles. For example, if I add height and width as fields and if I enter some values in that fields, Image(Html field) styles needs to change corresponding to height and width.

Code:

​​class ImagePreview(models.Model):
_name = 'image.preview'

images = fields.Binary(string='images')

width = fields.Float(string='Width')
height = fields.Float(string='Height')
preview = fields.Html(string="Preview", compute='img')

def img(self):
    with io.BytesIO(base64.b64decode(bytes(self.images, 'utf-8'))) as f:
        photo = f.read()
    htmlString = "<div><img src='" + str(photo) + "'></div>"
    self.preview = htmlString
    return

XML

   <record id="preview_form_view" model="ir.ui.view">
<field name="name">form</field>
<field name="model">image.preview</field>
<field name="arch" type="xml">
<form string="Discount Ribbons">
<sheet>
<group>
<group>
<field name="images" widget="image" class="oe_avatar" string="Image"/>
</group>
<group>
<div>
<field name="preview" widget="Html"/>
</div>
</group>
</group>
<group>
    <field name="width" string = 'Width'/>
<field name="height" string = 'Height'/>
</group>
            </sheet>
</form>
</field>
</record>
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

check the following question and app mentioned in that post

https://www.odoo.com/forum/help-1/question/how-to-show-image-for-html-field-in-template-odoo11-145240

https://www.odoo.com/apps/modules/12.0/html_image_url_extractor/

Regards

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ย. 21
5468
0
ก.พ. 21
1905
1
ก.ค. 19
2898
2
เม.ย. 17
10775
2
ม.ค. 25
3951