Odoo | 基础 | 初识系统-ORM之字段属性对象Field
字段属性对象Field
Model的字段属性对应数据表中的相应字段,pg表中不同的字段有不同类型,Odoo也为其封装了相应的类型对象
Field类型的属性:
- type = None 字段类型
- relational = False 是否是关联字段
- translate = False 字段是否翻译
- column_type = None 数据库字段类型
- column_format = '%s' 字段提示信息
- slots = {
'args': EMPTY_DICT, # _init()的设置参数
'_attrs': EMPTY_DICT, # the field's non-slot attributes
'_module': None, # 字段的模块名称
'_setup_done': None, # 字段设置状态: None, 'base' or 'full'
'automatic': False, # 是否是自动创建的字段 ("magic" field)
'inherited': False, # 是否是继承的字段 (_inherits)
'name': None, # 字段名称
'model_name': None, # 字段所在的模型名称
'comodel_name': None, # 关联字段的模型名称
'store': True, # 字段值是否保存到数据库
'index': False, # 是否在数据库中为字段添加索引
'manual': False, # 是否是自定义字段
'copy': True, # 字段值是否可以复制
'depends': (), # 字段的依赖集合
'recursive': False, # 是否自己依赖自己
'compute': None, # 计算字段的计算方法
'compute_sudo': False, # 字段是否以admin重新计算
'inverse': None, # inverse(recs) inverses field on recs
'search': None, # search(recs, operator, value) searches on self
'related': None, # 依赖字段的名称
'related_sudo': True, # whether related fields should be read as admin
'company_dependent': False, # whetherself
is company-dependent (property field)
'sparse': None, # the name of the corresponding serialized field, if any
'default': None, # 字段默认值
'string': None, # 字段说明
'help': None, # 字段提示
'readonly': False, # 是否只读
'required': False, # 是否必填字段
'states': None, # set readonly and required depending on state
'groups': None, # csv list of group xml ids
'change_default': False, # whether the field may trigger a "user-onchange"
'deprecated': None, # whether the field is deprecated
'related_field': None, # corresponding related field
'group_operator': None, # 能够执行聚合的操作
'group_expand': None, # name of method to expand groups in read_group()
'prefetch': True, # whether the field is prefetched
}
Odoo封装的字段对象主要有:
- Boolean
- Integer
- Float
- Monetary
- Char
- Text
- Html
- Date
- Datetime
- Binary
- Selection
- Reference
- Many2one
- One2many
- Many2many
Boolean
Boolean字段的type值为boolean;column_type值为('bool', 'bool')
Boolean对应pg的字段类型为boolean
例:
active = fields.Boolean(default=True, help=u"设置字段是否有效")
Integer
Integer字段的type值为integer;column_type值为('int4', 'int4')
_slots = { 'group_operator': 'sum', }
Integer对应pg的字段类型为4个字节的integer,并且能执行sum的聚合操作
例:
sequence = fields.Integer(string=u'序号', default=1)
Float
Float字段type值为float;column_type值为('numeric', 'numeric')或('float8', 'double precision')
_slots = {'_digits': None, 'group_operator': 'sum',}
Float对应pg的字段类型为8个字节的double或变长的numeric,并且能执行sum聚合操作
例:
product_qty = fields.Float(string=u'产品数量', digits=dp.get_precision('Product Unit of Measure'), required=True, index=True)
Monetary
Monetary字段的type值为monetary;column_type值为('numeric', 'numeric')
_slots = {'currency_field': None, 'group_operator': 'sum', }
Monetary 对应pg的字段类型为变长的numeric,并且能执行sum聚合操作
例:
amount = fields.Monetary(string=u'金额', currency_field='company_currency_id')
Char
Char字段的type值为char;column_type值为('varchar', 'VARCHAR')
Char对应pg的字段类型为变长的VARCHAR
例:
name = fields.Char(string=u'名称', index=True, required=True)
Text
Text字段的type值为text;column_type值为('text', 'text')
Text对应pg的字段类型为长文本类型的text
例:
comment = fields.Text(string=u'评论')
Html
Html字段的type值为text;column_type值为('text', 'text')
Html对应pg的字段类型为长文本类型的text; Html是特殊的Text该字段能保存html代码
例:
comment = fields.Html(string=u'评论')
Date
Date字段的type值为date;column_type值为('date', 'date')
Date对应pg的字段类型为日期类型的date
例:
start_date = fields.Date(string=u'开始日期', default=fields.Date.today)
Datetime
Datetime字段的type值为datetime;column_type值为('timestamp', 'timestamp')
Datetime对应pg的字段类型为无时区的日期时间类型的timestamp
例:
start_time = fields.Date(string=u'开始时间', default=fields.Date.now)
Binary
Binary字段的type值为binary;column_type值为('bytea', 'bytea')
Binary对应pg的字段类型为二进制类型bytea
Selection
Selection字段的type值为selection;column_type值为('int4', 'integer')或('varchar', 'VARCHAR')
Selection对应pg的字段类型为4个字节的interger或者是不定长的varchar
例:
state = fields.Selection(selection=[('draft',u'草稿'), ('done', u'完成')], default='draft')
Reference
Reference字段的type值为reference;column_type值为('varchar', 'VARCHAR')
Reference对应pg的字段类型为不定长的varchar
Many2one
Many2one字段的type值为many2one;column_type值为('int4', 'int4')
_slots = {'ondelete': 'set null', 'auto_join': False, 'delegate': False, }
Many2one是一个多对一的外表关联字段,对应pg的字段类型是4个字节的integer
例:
partner_id = fields.Many2one(comodel_name='res.partner', string=u'业务伙伴')
One2many
One2many字段的type值为one2many;
_slots = {'inverse_name': None, 'auto_join': False, 'limit': None,'copy': False,}
One2many是一个一对多的关联字段,与Manyone形成呼应
例:
stock_quant_ids = fields.One2many(comodel_name='stock.quant', inverse_name='product_id')
Many2many
Many2many字段的type值为many2many;
_slots = {'relation': None, 'column1': None, 'column2': None, 'auto_join': False, 'limit': None,}
many2many是一个多对多的关联字段
例:
sale_line_ids = fields.Many2many(comodel_name='sale.order.line', relation='sale_order_line_invoice_rel', column1='invoice_line_id', column2='order_line_id', string='Sale Order Lines', readonly=True)
From:http://www.jianshu.com/p/76d88e2bd5db
Odoo | 基础 | 初识系统-ORM之字段属性对象Field相关推荐
- solor的字段属性+复制域字段+动态域字段
schema.xml中配置的是索引库 域字段和域字段的类型 1) 字段属性: <field name="id" type="string" indexed ...
- 初识mysql数据字段属性_MySQL数据库~~~~初识、基础数据类型
一 数据库初识 1.1 什么是数据库 数据库(DataBase,简称DB),简而言之可视为电子化的文件柜----存储电子文件的处所,用户可以对文件中的数据运行新增,截取,更新,删除等操作. 所谓数据库 ...
- odoo ORM研究3 - odoo fields常用的字段属性
之前我们已经讲解了odoo ORM中的一些对字段常用的API操作方法,今天我们继续研究一下Odoo orm中字段的一些通用属性字段的使用,学会它们可以为自己创建数据映射并使用有更好的帮助. 通用字段属 ...
- 2.odoo13的学习(odoo中的模型、模型类属性、字段属性等)
目录 1.什么是模型 2.模型的定义 2.1 模型的位置 2.2 初始模型类 2.3 模型类的常用属性 2.4 模型类字段的属性参数 2.5 模型类创建好后,odoo默认创建一些字段 2.6 初始模型 ...
- 《地理信息系统基础实例操作100例》-实验15 设置字段属性域(无法创建要素问题)
<地理信息系统基础实例操作100例>-实验15 设置字段属性域(无法创建要素问题) 零.观前须知 一.基本流程 二.所遇问题 三.解决方法(之一) (一)ArcCatalog操作 (二)A ...
- ArcGIS二次开发基础教程(04):有关字段的操作和简单属性及空间查询
ArcGIS二次开发基础教程(04):有关字段的操作和简单属性及空间查询 属性 字段的添加.删除和查找 IFeatureLayer GetLayerByName(string name) {ILaye ...
- Odoo 模型、py字段属性、view字段属性使用
数据模型的设计: 区分实体模型.瞬态模型.抽象模型. 实体模型:数据需要持久化存储在数据库中. 瞬态模型:向导,临时数据,不需要持续化在数据库中的数据. 抽象模型:定义的底层模型.供其他实体模型继承的 ...
- ArcGis国土空间”一张图”填报操作技巧(四)零编程基础批量添加字段并设置字段属性
向表或要素类表.要素图层和/或带属性表的栅格添加字段并设置字段属性,是我们在数据建库或处理时常常要用到的操作,实现的方法非常多. 一.逐一添加字段的常见操作 1.打开属性表--添加字段. 2.使用字段 ...
- 零基础如何系统学习Python?Python入门必看
零基础如何系统学习python,绝大多数零基础转行者学习编程的目的就是想找一份高薪有发展前景的工作,哪个编程语言就业前景好越值得学习.零基础的同学学Python是一个不错的选择. 零基础学习pytho ...
最新文章
- oracle scn与数据恢复,SCN与数据库恢复的关系
- linux ps(process status) 命令详解
- Intel Realsense D435 通过识别目标的像素坐标和深度值(使用内参intrinsics)获取目标点的真实坐标
- 阿里云2011.9.17招聘会笔试题
- Exception in thread “main“ java.lang.NoSuchMethodError: scala.collection.mut
- MySQL——通过EXPLAIN分析SQL的执行计划
- HP Unix vsftp服务配置
- 初学者应该如何有效率的系统学习Python开发
- linux 磁盘控制器,linux – 戴尔R710上的PERC 6 / i RAID:单个控制器上的慢速磁盘…… RAID10?...
- 小汤学编程之JDBC番外篇——DBUtil工具类
- es6删除数组某项_es6删除数组元素或者对象元素的方法介绍(代码)
- Java败给Python?不!我有话说
- 【深度学习原理】交叉熵损失函数的实现
- 【Live2D】关于我在初试live2d时遇到的问题和看法
- html坦克大战js代码包,js实现坦克大战游戏
- selenium chrome历史版本docker镜像分享
- 如何将国际音标插入到Word中? | 怎么打48个国际音标?
- 遇到问题---linux--crontab输出重定向不生效最全可能原因收集和解决
- opencv学习-高斯金字塔和拉普拉斯金字塔
- 教你用Python向MySQL中插入一百万条测试数据