Odoo Help


Avatar image in new api

Alexei R. Acosta
on 12/4/14, 11:17 AM 2,468 views

I want to use an avatar image in a class, using the new odoo api, but i'm having some errors:

    image = fields.Binary("Image", default='_get_default_image',
                         help="This field holds the image used as avatar for this student, limited to 1024x1024px")
    image_medium = fields.Binary(string="Medium-sized image", store=True, compute="_get_image",   inverse='_set_image',
                                help="Medium-sized image of this contact. It is automatically " \
                                     "resized as a 128x128px image, with aspect ratio preserved. " \
                                     "Use this field in form views or some kanban views.")

these are the functions:

    def _get_default_image(self):
        image_path = openerp.modules.get_module_resource('af', 'static/src/img', 'default_image.png')
        return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64'))
    def _get_image(self):
        return dict((s.id, tools.image_get_resized_images(s.image)) for s in self)
    def _set_image(self, name, value, args):
        return self.write({'image': tools.image_resize_image_big(value)})

What i'm doing wrong? What i have to change or add?

Any help, thanks ins advanced.


Any help?

Alexei R. Acosta
on 12/5/14, 9:34 AM

You may want to edit your post and indicate what the errors are.

on 12/5/14, 12:48 PM
On 3/10/15, 8:50 AM

The solution here ;)


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 12/4/14, 11:17 AM
Seen: 2468 times
Last updated: 3/16/15, 8:10 AM