How to get in openerp all objects from a class?

南笙酒味 提交于 2019-12-08 07:54:50

问题


I need to get all objects from a class and iterate through them. I tried this, but without any results:

def my_method(self, cr, uid, ids, context=None):
    pool_obj = pooler.get_pool(cr.dbname)
    my_objects=pool_obj.get('project.myobject')
    #here i'll iterate through them...

How can I get in 'my_objects' variable all objects of class 'project.myobject'?


回答1:


You have to search with empty parameters to get all the ids of existing objects, like:

myobj = pool.get('project.myobject')
ids = myobj.search(cr, uid, [])

Then you can browse or read them passing an id or the list of ids.




回答2:


It seems you forget to import pooler.

from openerp import pooler

May it will help you.



来源:https://stackoverflow.com/questions/16101719/how-to-get-in-openerp-all-objects-from-a-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!