Community: CMS / eCommerce Experts archivos de la lista de correo


Re: How do I dump the data from a model?

- 16/12/2014 19:11:12
thanks for the response. I often ask questions on the forum, but about
1 in 3 gets an answer. It would be nice if there was a mailing list
specifically for odoo development questions.

This is what I ended up using to inspect models:

        def model_data(obj):
            fields_dict = {}
            for key in obj.fields_get():
                fields_dict[key] = obj[key]
            return fields_dict

So it returns something like this (for an instance of the survey.survey model):

{'__last_update': '2014-12-15 19:26:23',
 'column_nb': u'12',
 'comment_count_as_answer': False,
 'comments_allowed': False,
 'comments_message': u'If other, precise:',
 'constr_error_msg': u'This question requires an answer.',
 'constr_mandatory': False,
 'create_date': '2014-12-15 19:26:23',
 'create_uid': res.users(1,),
 'description': False,
 'display_mode': u'columns',
 'display_name': u'Product & Feature Suggestions',
 'id': 4,
 'labels_ids': survey.label(17, 18),
 'labels_ids_2': survey.label(),
 'matrix_subtype': u'simple',
 'question': u'Product & Feature Suggestions',
 'sequence': 10,
 'survey_id': survey.survey(1,),
 'type': u'multiple_choice',
 'user_input_line_ids': survey.user_input_line(21, 22),
 'validation_email': False,
 'validation_error_msg': u'The answer you entered has an invalid format.',
 'validation_length_max': 0,
 'validation_length_min': 0,
 'validation_max_date': False,
 'validation_max_float_value': 0.0,
 'validation_min_date': False,
 'validation_min_float_value': 0.0,
 'validation_required': False,
 'write_date': '2014-12-15 19:26:23',
 'write_uid': res.users(1,)}

Initially I tried to make it recursively lookup linked objects, such
as user_input_line_ids and write_uid, but since odoo appears to lazy
load related objects and they have circular relationships, that didn't
pan out too well.

On 12/6/14, Pedro Manuel Baeza Romero <> wrote:
> Although this is not the best list to make this kind of questions (I think
> the forum fits better), I'll tell you that you can use . _columns variable,
> that list all the fields that the model has.
> Regards.
> 2014-12-05 23:39 GMT+01:00 Darrel Grant < [1] > :
> If I use self.pool.get('model').browse(ID)
> I get a model object which also seems to automatically load the
> relationships.
> How do I dump all of the key/value pairs of just the data from the
> database from that returned model object?
> If I use vars() on the object, it returns literally hundreds of
> things, because it dumps all of the models various helper functions. I
> also found get_fields(), which dumps a lot of schema information, but
> none of the data (and it's not very readable for something with a lot
> of relationships like product_product).
> What I want is to see the fields and data so I can better understand
> the actual data in the business objects. Is there a helper method
> somewhere in osv.Model which does this?
> Darrel
> _______________________________________________
> Mailing-List:
> [2]
> Post to: mailto: [3]
> Unsubscribe: [4]
> _______________________________________________
> Mailing-List:
> Post to:
> Unsubscribe:
> [1]
> [2]
> [3]
> [4]