Registry.get 的定义 程序代码: [url=][选择][/url]
def get(self, model_name): """ Return a model for a given name or None if it doesn't exist.""" return self.models.get(model_name)
最后看看obj.__init__(pool, cr)初始化对象,做了什么动作? 程序代码: [url=][选择][/url]
def __init__(self, pool, cr): """ Initialize a model and make it part of the given registry. - copy the stored fields' functions in the osv_pool, - update the _columns with the fields found in ir_model_fields, - ensure there is a many2one for each _inherits'd parent, - update the children's _columns, - give a chance to each field to initialize itself. """ pool.add(self._name, self) self.pool = pool
pool.add(self._name, self) 定义如下: 程序代码: [url=][选择][/url]
def add(self, model_name, model): """ Add or replace a model in the registry.""" self.models[model_name] = model
到这里应该很非常清楚,Registry.models 保存了对象的 model 信息。这样多个对象继承同一父类时,按照加载顺序先后动态构建相关的类。