当前位置: 首页 > 工具软件 > Model Search > 使用案例 >

Odoo12 Model属性简介

罗浩然
2023-12-01

Model定义时可选的属性定义及含义介绍


@pycompat.implements_to_string
class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
    """ Base class for Odoo models.

    Odoo models are created by inheriting: Odoo模型是通过继承创建的:

    *   :class:`Model` for regular database-persisted models
        类:用于常规数据库持久模型的“模型”

    *   :class:`TransientModel` for temporary data, stored in the database but
        automatically vacuumed every so often
        :类: ' TransientModel '用于临时数据,存储在数据库中经常自动清理

    *   :class:`AbstractModel` for abstract super classes meant to be shared by
        multiple inheriting models
        :类: ' AbstractModel ',用于表示要共享的抽象超类 多个继承模型

    The system automatically instantiates every model once per database. Those 系统对每个数据库自动实例化每个模型一次。
    instances represent the available models on each database, and depend on 这些实例表示每个数据库上的可用模型,
    which modules are installed on that database. The actual class of each ,并依赖于这些模型数据库上安装了哪些模块。
    instance is built from the Python classes that create and inherit from the 每个类的实际类实例是由Python类构建的相应的模型创建和继承。
    corresponding model.

    Every model instance is a "recordset", i.e., an ordered collection of 每个模型实例都是一个“记录集”,即的有序集合模型的记录。
    records of the model. Recordsets are returned by methods like  记录集通过以下方法返回:方法:~.browse`, :方法:`~.search`或字段访问。
    :meth:`~.browse`, :meth:`~.search`, or field accesses. Records have no  记录没有显式表示:一条记录表示为一条记录的记录集记录。
    explicit representation: a record is represented as a recordset of one
    record.

    To create a class that should not be instantiated, the _register class
    attribute may be set to False.  要创建不应实例化的类,请使用_register类属性可以设置为False。
    """
    _auto = False               # don't create any database backend 不创建任何数据库后端
    _register = False           # not visible in ORM registry  在ORM注册表中不可见
    _abstract = True            # whether model is abstract  模型是否抽象
    _transient = False          # whether model is transient  模型是否临时

    _name = None                # the model name  模型名称
    _description = None         # the model's informal name  模型的描述信息
    _custom = False             # should be True for custom models only 应该只对自定义模型成立

    _inherit = None             # Python-inherited models ('model' or ['model'])  python继承模型
    _inherits = {}              # inherited models {'parent_model': 'm2o_field'}  多个继承模型
    _constraints = []           # Python constraints (old API)  python方式约束(旧API)

    _table = None               # SQL table name used by model 模型使用的SQL表名
    _sequence = None            # SQL sequence to use for ID field 用于ID字段的SQL序列
    _sql_constraints = []       # SQL constraints [(name, sql_def, message)]  数据库约束

    _rec_name = None            # field to use for labeling records  字段用于标记记录
    _order = 'id'               # default order for searching results  搜索结果的默认顺序
    _parent_name = 'parent_id'  # the many2one field used as parent field  many2one字段用作父字段
    _parent_store = False       # set to True to compute parent_path field  设置为True以计算parent_path字段
    _date_name = 'date'         # field to use for default calendar view  用于默认日历视图的字段
    _fold_name = 'fold'         # field to determine folded groups in kanban views  字段确定看板视图中的折叠组

    _needaction = False         # whether the model supports "need actions" (see mail) 模型是否支持“需求操作”(见邮件)
    _translate = True           # False disables translations export for this model  False禁用此模型的翻译导出

    _depends = {}               # dependencies of models backed up by sql views  由sql视图支持的模型的依赖性
                                # {model_name: field_names, ...}
 类似资料: