تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
5293 أدوات العرض

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







الصورة الرمزية
إهمال

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

الكاتب أفضل إجابة

thank U

it works!

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
مايو 23
17163
1
مارس 15
6734
1
أبريل 15
4778
2
فبراير 24
3271
1
يونيو 22
3115