Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
5190 Widoki

Hi

here my situation

class ProductImage(models.Model):
    _name = "product.images"
    _description = "Additional Product Images"
    _order = "sequence"

    sequence = fields.Integer('Sequence',)
    product_id = fields.Many2one('product.product', 'Product Variant', required=False)
    product_tmpl_id = fields.Many2one('product.template', 'Product Template', required=False)
    name = fields.Char('Image Name', size=160)
    image = fields.Binary("Image", attachment=True, required=True)

and on Product model

    image_ids = fields.One2many('product.images',
                                'product_id',
                                'Additional Images')

I'd like to replace the default image on product form with (for example) the first image from image_ids.

So I've created a computed method

@api.depends('image_ids')
def _compute_main_image(self):
     if self.id and self.image_ids:
         self.main_image = self.image_ids[0]

for a new Binary field

main_image = fields.Binary("Main image",
                           compute='_compute_main_image',
                           store=False, )

and I'm trying to show that image on the form

<xpath expr="//field[@name='image_medium']"  position="attributes">
       <field name="main_image" widget="image" class="oe_avatar"/>
</xpath>

but I received "The image couldn't display ..."

can someone help me?

Thank's.

Pietro Conconi







Awatar
Odrzuć

main_image should be a binary field and you should give binary values

Autor Najlepsza odpowiedź

thank U

it works!

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
maj 23
17044
1
mar 15
6605
1
kwi 15
4711
2
lut 24
3113
1
cze 22
3043