onchange装饰器具体是如何触发的?
-
1.示例
from odoo import models, fields,api
class AModel(models.Model):
_name = 'a.model.name'
field1 = fields.Char()
field2 = fields.Integer(string="an other field")@api.onchange('field1', 'field2') # 当这两个字段值改变时调用该函数
def check_change(self):
if self.field1 < self.field2:
self.field3 = True2.api.py
def onchange(*args):
""" Return a decorator to decorate an onchange method for given fields.
Each argument must be a field name """
return attrsetter('_onchange', args)def attrsetter(attr, value):
""" Return a function that setsattr
on its argument and returns it. """
return lambda method: setattr(method, attr, value) or method'''
The following attributes are used, and reflected on wrapping methods:- method._onchange: set by @onchange, specifies onchange fields
- method.clear_cache: set by @ormcache, used to clear the cache
On wrapping method only:
- method._api: decorator function, used for re-applying decorator
- method._orig: original method
'''
WRAPPED_ATTRS = ('module', 'name', 'doc', '_constrains',
'_depends', '_onchange', '_returns', 'clear_cache')INHERITED_ATTRS = ('_returns',)
- 问题:
请问当'field1', 'field2'字段值发生变化时,是如何触发调用装饰器函数的?_onchange 是fields类的一个内部方法吗?可是在api,fields和models里都没找到哦,哪位大牛能帮解答一下?谢谢