Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
10301 Visualizações

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>
Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
2
set. 21
4925
0
fev. 21
1398
1
jul. 19
2522
2
abr. 17
10130
2
jan. 25
3516