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 to only fetch specific fields from the ORM/database?

By
Kasper Souren
on 9/22/14, 10:46 AM 803 views

I'm starting to write some actual working Odoo code. That's great. But now I have this slow ORM stuff here:

            obj = pool[model]
            ids = obj.search(cr, uid, [], context=context)
            items = obj.browse(cr, uid, ids, context=context)
            custom_map = dict([(i.custom_field, i.id)
                                              for i in items
                                              if i.custom_field != ''])

I would like to fetch only the custom_field (mapped to the id), not the rest. But I have a feeling that now it's actually fetching all data (which unfortunately includes base64 images). Is there an easy way to only fetch the two fields I need? (i.e. id and custom_field)

1

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 9/22/14, 10:49 AM

You only need to use read:

obj.read(cr, uid, ids, fields=[field1, field2])

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: 9/22/14, 10:46 AM
Seen: 803 times
Last updated: 3/16/15, 8:10 AM