odoo 关系字段(关联关系)
Many-to-one关联
publisher_id = fields.Many2one(comodel_name= 'res.partner', domain='',context={},ondelete='',auto_join='',delegate='',string='Publisher')
many-to-one模型字段在数据表中创建一个字段,并带有指向关联表的外键,其中为关联记录的数据库 ID。以下是many-to-one字段可用的关键字参数:
- ondelete定义关联记录删除时执行的操作:context是一个数据字典,可在浏览关联时为网页客户端传递信息,比如设置默认值。
- set null (默认值): 关联字段删除时会置为空值
- restricted:抛出错误阻止删除
- cascade:在关联记录删除时同时删除当前记录
- domain是一个域表达式:使用一个元组列表过滤记录来作为关联记录选项。
- auto_join=True允许ORM在使用关联进行搜索时使用SQL连接。使用时会跳过访问安全规则,用户可以访问安全规则不允许其访问的关联记录,但这样 SQL 的查询会更有效率且更快。
- delegate=True 创建一个关联记录的代理继承。使用时必须设置required=True和ondelete=’cascade’
One-to-many反向关联
published_book_ids = fields.One2many(
comodel_name= 'library.book', # related model
Many-to-many关联
author_ids = fields.Many2many(
class Many2many(_RelationalMulti):
""" Many2many field; the value of such a field is the recordset.
:param comodel_name: name of the target model (string)
The attribute ``comodel_name`` is mandatory except in the case of related
fields or field extensions.
:param relation: optional name of the table that stores the relation in
the database (string)
:param column1: optional name of the column referring to "these" records
in the table ``relation`` (string)
:param column2: optional name of the column referring to "those" records
in the table ``relation`` (string)
The attributes ``relation``, ``column1`` and ``column2`` are optional. If not
given, names are automatically generated from model names, provided
``model_name`` and ``comodel_name`` are different!
:param domain: an optional domain to set on candidate values on the
client side (domain or string)
:param context: an optional context to use on the client side when
handling that field (dictionary)
:param limit: optional limit to use upon read (integer)
"""
odoo 关系字段(关联关系)的更多相关文章
- (原创)odoo关系字段在视图中的行为控制 总结
字段类型 选项或属性 格式示例 描述 many2one , many2many_tags(widget) no_create options='{"no_create":True} ...
- odoo Model字段的参数
odoo Model字段的参数 class Field(object): """ The field descriptor contains the field defi ...
- Python之关系字段
参考:https://blog.csdn.net/pugongying1988/article/details/72870264 关系字段:一对一,多对一,多对多 一对一: 现在有很多一对一辅导班, ...
- odoo 的字段。orm对象
OpenERP ORM 对象方法列表 OpenERP对象支持的字段类型有,基础类型:char, text, boolean, integer, float, date, time, datetim ...
- Django框架之第六篇(模型层)--单表查询和必知必会13条、单表查询之双下划线、Django ORM常用字段和参数、关系字段
单表查询 补充一个知识点:在models.py建表是 create_time = models.DateField() 关键字参数: 1.auto_now:每次操作数据,都会自动刷新当前操作的时间 2 ...
- python 之 Django框架(ORM常用字段和字段参数、关系字段和和字段参数)
12.324 Django ORM常用字段 .id = models.AutoField(primary_key=True):int自增列,必须填入参数 primary_key=True.当model ...
- 06 ORM常用字段 关系字段 数据库优化查询
一.Django ORM 常用字段和参数 1.常用字段 models中所有的字段类型其实本质就那几种,整形varchar什么的,都没有实际的约束作用,虽然在models中没有任何限制作用,但是还是要分 ...
- django--orm关系字段(ForeignKey、OneToOneField、ManyToManyField)详解
django中的关系字段 1.ForeignKey字段,即外键字段,对应一对多的情况,列如:一本书对应一个出版社,一个出版社可对应多本书. 2.ManyToManyFiled字段,即多对多字段,对应数 ...
- Django:ORM关系字段
一,ForeignKey 外键类型在ORM中用来表示外键关联关系,一般把ForeignKey字段设置在 '一对多'中'多'的一方. ForeignKey可以和其他表做关联关系同时也可以和自身做关联关系 ...
随机推荐
- quartz定时任务表达式案例
表示式 说明 "0 0 12 * * ? " 每天12点运行 "0 15 10 ? * *" 每天10:15运行 "0 15 10 * * ?&quo ...
- jenkins配置jdk、git、maven
进入首页->系统管理->全局工具配置 配置jdk 查找jdk安装路径 如果是容器版jenkins,就登进容器里面查看jdk路径 [root@test2 ~]# echo $JAVA_HOM ...
- GlusterFS集群
使用架构: 2台机器安装 GlusterFS 组成一个 Distributed Replicated Volumes集群 192.168.0.92 服务端 192.168.0.93 服务端 192.1 ...
- DS18b20温度传感器基础使用
认识管脚 认识唯一标示的64位地址序列号 寄存器数据译码成温度值(下面只针对12位转化的,还有9..10等其他位的转化方式,不同位的转化,其精度也不同) 传感器存储器 配置寄存器使用说明 DS18b2 ...
- HTML基础知识自学教程
HTML 是用来描述网页的一套标记标签,是我们在web前端开发中的基础.下面PHP程序员雷雪松主要结合自己的经验给大家分享下HTML的基础知识,以及在自学过程中一些比较常用的和重要的HTML知识点. ...
- 【CodeForces - 598D】Igor In the Museum(bfs)
Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...
- 安装zabbix4.0 LTS
一.环境准备 1.https://www.zabbix.com/download?zabbix=4.4&os_distribution=centos&os_version=7& ...
- Prettier格式化配置
HTML/CSS/JS/LESS 文件的 prettier 格式化规则 { // 使能每一种语言默认格式化规则 "[html]": { "editor.defaultFo ...
- 进行hcmcloud 数据库备份以及设置的处理过程.
导入数据库以及简单设置. 最近进行了一个数据库备份的简单工作: create database hcmcloud create user hcm with password 'Test6530' 执行 ...
- 啃掉Hadoop系列笔记(04)-Hadoop运行模式之伪分布式模式
伪分布式模式等同于完全分布式,只是她只有一个节点. 一) HDFS上运行MapReduce 程序 (1)配置集群 (a)配置:hadoop-env.sh Linux系统中获取jdk的安装路径: