Odoo Help


How can I add images in odoo surveys

on 11/4/16, 11:33 PM 597 views

Hi, I'm working on a job application which requires a survey

what I need to do is to add  pictures as part of a multiple choice question on a quiz, how can I add it?

On 11/5/16, 5:56 AM

well, I tried to add it myself, but I got an error of:

Integrity Error

The operation cannot be completed, probably due to the following:

- deletion: you may be trying to delete a record while other records still reference it- creation/update: a mandatory field is not correctly set

[object with reference: page_id - page.id]

Here's my code:

class survey_question(osv.osv):

    _inherit = 'survey.question'

    def _get_image(self, cr, uid, ids, name, args, context=None):

        result = dict.fromkeys(ids, False) for obj in self.browse(cr, uid, ids, context=context):

            result[obj.id] = tools.image_get_resized_images(obj.image) return result

    def _set_image(self, cr, uid, id, name, value, args, context=None):

        return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context)

    _columns = { 'image': fields.binary("Photo", help="This field holds the image used as photo for the question, limited to 1024x1024px."), 'image_medium': fields.function(_get_image, fnct_inv=_set_image, string="Medium-sized photo", type="binary", multi="_get_image", store = { 'survey.question': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), }, help="Medium-sized photo. It is automatically "\ "resized as a 128x128px image, with aspect ratio preserved. "\ "Use this field in form views or some kanban views."), 'image_small': fields.function(_get_image, fnct_inv=_set_image, string="Small-sized photo", type="binary", multi="_get_image", store = { 'survey.question': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), }, help="Small-sized photo. It is automatically "\ "resized as a 64x64px image, with aspect ratio preserved. "\ "Use this field anywhere a small image is required."),


Ahmed M.Elmubarak
On 11/5/16, 5:03 AM

Hello Again Youta !

IMHO, I think it is not easy do add such thing to the survey module "I mean, this is not direct and straight forward such as normal models',

You can take a look at the OCA survey contribution , and you can also check this module it adds a new type of questions to survey ...

Hope this could helps a little bit ..



in your python file

image = fields.Binary('Image')

In xml

<field name="image" widget="image"/>

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

1 follower(s)


Asked: 11/4/16, 11:33 PM
Seen: 597 times
Last updated: 11/5/16, 5:56 AM