Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
5274 Näkymät

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







Avatar
Hylkää

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

Tekijä Paras vastaus

thank U

it works!

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
3
toukok. 23
17139
1
maalisk. 15
6722
1
huhtik. 15
4771
2
helmik. 24
3242
1
kesäk. 22
3111