本文介绍了如何在openerp中获取类中的所有对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从一个类中获取所有对象,并遍历它们.我试过了,但是没有任何结果:
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...
如何在"my_objects"变量中获取"project.myobject"类的所有对象?
How can I get in 'my_objects' variable all objects of class 'project.myobject'?
推荐答案
您必须使用空参数进行搜索才能获取现有对象的所有ID,例如:
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, [])
然后,您可以通过ID或ID列表浏览或阅读它们.
Then you can browse or read them passing an id or the list of ids.
这篇关于如何在openerp中获取类中的所有对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!