_global_seq =iter(itertools.count())classField(MetaField('DummyField',(object,),{})):""" The field descriptor contains the field definition, and manages accesses
and assignments of the corresponding field on records. The following
attributes may be provided when instanciating a field:
字段描述符包含字段定义并管理访问以及记录中相应字段的赋值。以下属性可以在实例化字段时提供
:param string: the label of the field seen by users (string); if not
set, the ORM takes the field name in the class (capitalized).
用户看到的字段标签(字符串);如果没有设置,ORM将类中的字段名(大写)作为名称。
:param help: the tooltip of the field seen by users (string)
# 用户看到的字段的提示信息(字符串)
:param readonly: whether the field is readonly (boolean, by default ``False``)
# 字段是否只读(布尔值,默认为False)
:param required: whether the value of the field is required (boolean, by default ``False``)
# 字段的值是否必输(布尔值,默认为False)
:param index: whether the field is indexed in database (boolean, by default ``False``)
# 是否为该字段在数据库创建索引(布尔值,默认为False)
:param default: the default value for the field; this is either a static
value, or a function taking a recordset and returning a value; use
``default=None`` to discard default values for the field
# 字段的默认值;这两个都是静态的值,或获取记录集并返回值的函数;使用‘default=None’放弃该字段的默认值
:param states: a dictionary mapping state values to lists of UI attribute-value
pairs; possible attributes are: 'readonly', 'required', 'invisible'.
Note: Any state-based condition requires the ``state`` field value to be
available on the client-side UI. This is typically done by including it in
the relevant views, possibly made invisible if not relevant for the
end-user.
# 将状态值映射到UI属性值列表的字典,可能的属性有:'readonly', 'required', 'invisible'。
# 任何基于状态的条件都要求字段值为可用于客户端UI。
# 这通常是通过包含它来完成的相关的视图,如果不是相关的,可能是不可见的终端用户。
:param groups: comma-separated list of group xml ids (string); this
restricts the field access to the users of the given groups only
# 组: xml ids的逗号分隔列表(字符串);这仅限制对给定组的用户的字段访问
:param bool copy: whether the field value should be copied when the record
is duplicated (default: ``True`` for normal fields, ``False`` for
``one2many`` and computed fields, including property fields and
related fields)
# 当记录被复制时字段的值是否应该被复制(默认:' True '为正常字段,' False '为和计算字段,
# 包括属性字段和关联字段)
:param string oldname: the previous name of this field, so that ORM can rename
it automatically at migration
# 此字段的之前名称,以便ORM可以在迁移时对它自动完成重命名
.. _field-computed: 计算字段
.. rubric:: Computed fields
One can define a field whose value is computed instead of simply being
read from the database. The attributes that are specific to computed
fields are given below. To define such a field, simply provide a value
for the attribute ``compute``.
定义字段时,字段的值可以通过计算得到而非简单的从数据库读取。特定于计算的属性字段如下所示,
为了定义这样一个计算字段,最简单的方式即为提供一个‘compute’的属性。
:param compute: name of a method that computes the field # 字段的计算方法名称
:param inverse: name of a method that inverses the field (optional) # 反转字段的方法的名称(可选)
:param search: name of a method that implement search on the field (optional) # 在字段上实现搜索的方法的名称(可选)
:param store: whether the field is stored in database (boolean, by
default ``False`` on computed fields) # 计算字段是否存储于数据库,布尔值,默认为False
:param compute_sudo: whether the field should be recomputed as superuser # 是否应该将字段重新计算为超级用户
to bypass access rights (boolean, by default ``False``) # 绕过访问权限(布尔值,默认为' ' False ' ')
The methods given for ``compute``, ``inverse`` and ``search`` are model # 方法``compute``, ``inverse`` and ``search``
methods. Their signature is shown in the following example:: # 都为模型方法,它们的签名如下面的示例所示:
upper = fields.Char(compute='_compute_upper',
inverse='_inverse_upper',
search='_search_upper')
@api.depends('name')
def _compute_upper(self):
for rec in self:
rec.upper = rec.name.upper() if rec.name else False
def _inverse_upper(self):
for rec in self:
rec.name = rec.upper.lower() if rec.upper else False
def _search_upper(self, operator, value):
if operator == 'like':
operator = 'ilike'
return [('name', operator, value)]
The compute method has to assign the field on all records of the invoked
recordset. The decorator :meth:`odoo.api.depends` must be applied on
the compute method to specify the field dependencies; those dependencies
are used to determine when to recompute the field; recomputation is
automatic and guarantees cache/database consistency. Note that the same
method can be used for several fields, you simply have to assign all the
given fields in the method; the method will be invoked once for all
those fields.
# compute方法必须在调用的所有记录上分配字段记录集。必须使用装饰器:“odoo.api.depends”指定字段依赖项的计算方法;
# 这些依赖项用于确定何时重新计算字段;重新计算是自动和保证缓存/数据库一致性。
# 注意同样的方法可用于多个字段,只需为所有字段分配方法中给定的字段;该方法将被一次性调用这些字段。
By default, a computed field is not stored to the database, and is
computed on-the-fly. Adding the attribute ``store=True`` will store the
field's values in the database. The advantage of a stored field is that
searching on that field is done by the database itself. The disadvantage
is that it requires database updates when the field must be recomputed.
# 默认情况下,计算字段不会存储到数据库中,而是动态计算。添加属性'store=True'将存储字段在数据库中的值。
# 存储字段的优点是在该字段上的搜索由数据库本身完成。缺点当字段必须重新计算时,它需要数据库更新。
The inverse method, as its name says, does the inverse of the compute
method: the invoked records have a value for the field, and you must
apply the necessary changes on the field dependencies such that the
computation gives the expected value. Note that a computed field without
an inverse method is readonly by default.
# 逆方法,顾名思义,就是做计算的逆方法:调用的记录具有字段的值,您必须这样做对字段依赖项应用必要的更改,
# 以便计算给出了期望值。注意,没有计算字段默认情况下,逆方法是只读的。
The search method is invoked when processing domains before doing an
actual search on the model. It must return a domain equivalent to the
condition: ``field operator value``.
# 在执行之前处理域时调用搜索方法模型上的实际搜索。它必须返回一个等价于的domain条件:'字段操作符值'
.. _field-related: # 关联字段
.. rubric:: Related fields
The value of a related field is given by following a sequence of
relational fields and reading a field on the reached model. The complete
sequence of fields to traverse is specified by the attribute
# 相关字段的值由以下序列给出关系字段和读取所关联模型上的字段。完整的属性指定要遍历的字段序列
:param related: sequence of field names
Some field attributes are automatically copied from the source field if
they are not redefined: ``string``, ``help``, ``readonly``, ``required`` (only
if all fields in the sequence are required), ``groups``, ``digits``, ``size``,
``translate``, ``sanitize``, ``selection``, ``comodel_name``, ``domain``,
``context``. All semantic-free attributes are copied from the source
field.
# 某些字段属性会自动从源字段中复制而非重新定义:“string”、“help”、“readonly”、“required”(仅限如果序列中的所有字段都是必需的),
# “groups”, “numbers”, “size”,“translate”、“sanitize”、“selection”、“comodel_name”,“domain”,“context”。
# 所有没有语义的属性都是从源代码中复制的字段。
By default, the values of related fields are not stored to the database.
Add the attribute ``store=True`` to make it stored, just like computed
fields. Related fields are automatically recomputed when their
dependencies are modified.
# 默认情况下,关联字段的值不会存储于数据库中,增加属性``store=True``就可以使值存于数据库中,类似于计算字段。
# 关联字段会在依赖的字段发生改变之后自动进行重新计算。
.. _field-company-dependent: # 公司依赖字段
.. rubric:: Company-dependent fields
Formerly known as 'property' fields, the value of those fields depends
on the company. In other words, users that belong to different companies
may see different values for the field on a given record.
# 以前称为“property”字段,这些字段的值取决于在公司。换句话说,用户属于不同的公司可能在给定记录上看到字段的不同值。
:param company_dependent: whether the field is company-dependent (boolean) # 是否依赖于公司
.. _field-incremental-definition:
.. rubric:: Incremental definition
A field is defined as class attribute on a model class. If the model
is extended (see :class:`~odoo.models.Model`), one can also extend
the field definition by redefining a field with the same name and same
type on the subclass. In that case, the attributes of the field are
taken from the parent class and overridden by the ones given in
subclasses.
字段被定义为模型类上的class属性。如果模型是扩展的(参见:class: ' ~odoo.models.Model '),
通过重新定义具有相同名称和相同的字段来对继承的字段进行扩展.
在这种情况下,字段的属性是根据从父类的属性和子类中重新继承合并而来的。
For instance, the second class below only adds a tooltip on the field # 例如,第二个类只是增加help属性
``state``::
class First(models.Model):
_name = 'foo'
state = fields.Selection([...], required=True)
class Second(models.Model):
_inherit = 'foo'
state = fields.Selection(help="Blah blah blah")
"""type=None# type of the field (string) 字段类型
relational =False# whether the field is a relational one 字段是否是关联字段
translate =False# whether the field is translated 字段是否被翻译
column_type =None# database column type (ident, spec) 数据库字段类型
column_format ='%s'# placeholder for value in queries 查询中值的占位符
column_cast_from =()# column types that may be cast to this 可以转换为此类型的列类型
_slots ={'args': EMPTY_DICT,# the parameters given to __init__() 给__init__()的参数'_attrs': EMPTY_DICT,# the field's non-slot attributes 字段的non-slot属性'_module':None,# the field's module name 字段的模块名称'_modules':None,# modules that define this field 定义此字段的模块'_setup_done':None,# the field's setup state: None, 'base' or 'full' 字段的设置状态:None、'base'或'full''_sequence':None,# absolute ordering of the field 字段的绝对顺序'automatic':False,# whether the field is automatically created ("magic" field) 是否自动创建字段(“magic”字段)'inherited':False,# whether the field is inherited (_inherits) 字段是否被继承(_inherits)'inherited_field':None,# the corresponding inherited field 对应的继承字段'name':None,# name of the field 字段名'model_name':None,# name of the model of this field 此字段的模型的名称'comodel_name':None,# name of the model of values (if relational) 值模型的名称(如果是关系型)'store':True,# whether the field is stored in database 字段是否存储在数据库中'index':False,# whether the field is indexed in database 字段是否在数据库中建立索引'manual':False,# whether the field is a custom field 字段是否是自定义字段'copy':True,# whether the field is copied over by BaseModel.copy() 字段是否被BaseModel.copy()复制'depends':None,# collection of field dependencies 字段依赖项的集合'recursive':False,# whether self depends on itself 是否依赖于自己'compute':None,# compute(recs) computes field on recs 计算(recs)计算recs上的字段'compute_sudo':False,# whether field should be recomputed as admin 是否应将字段重新计算为admin'inverse':None,# inverse(recs) inverses field on recs 逆(recs)反转recs上的场'search':None,# search(recs, operator, value) searches on self 在self上搜索(recs,运算符,值)'related':None,# sequence of field names, for related fields 相关字段的字段名称序列'related_sudo':True,# whether related fields should be read as admin 相关字段是否应读为admin'company_dependent':False,# whether ``self`` is company-dependent (property field) “self”是否与公司相关(物业领域)'default':None,# default(recs) returns the default value 返回默认值'string':None,# field label 字段标签'help':None,# field tooltip 字段提示'readonly':False,# whether the field is readonly 字段是否只读'required':False,# whether the field is required 字段是否必输'states':None,# set readonly and required depending on state 根据状态设置readonly和required'groups':None,# csv list of group xml ids xml ids组的csv列表'change_default':False,# whether the field may trigger a "user-onchange" 字段是否会触发“user-onchange”'deprecated':None,# whether the field is deprecated 字段是否已弃用'related_field':None,# corresponding related field 相应的关联字段'group_operator':None,# operator for aggregating values 用于聚合值的运算符'group_expand':None,# name of method to expand groups in read_group() 在read_group()中展开组的方法的名称'prefetch':True,# whether the field is prefetched 是否预取字段'context_dependent':False,# whether the field's value depends on context 字段的值是否取决于上下文}
字段定义时可选的属性定义及含义介绍_global_seq = iter(itertools.count())class Field(MetaField('DummyField', (object,), {})): """ The field descriptor contains the field definition, and manages accesses ...