Odoo Help

Welcome!

This community 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.

0

How can I add images in odoo surveys

By
youta
on 11/4/16, 11:33 PM 109 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?

0
youta
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."),

    }

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


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 ..



0
shameem@aχoncoms
On 11/5/16, 4:05 AM

Youta,

in your python file

image = fields.Binary('Image')

In xml

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


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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