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

       inverse_name= 'publisher_id', # fields for "this" on related model
      domain='',
      context={},
     auto_join='',
     limit=0,
        string='Published Books')
 

Many-to-many关联

author_ids = fields.Many2many(

    comodel_name='res.partner', # 关联模型(必填)
    relation='library_book_res_partner_rel', # 关联表名
    column1='a_id', # 本记录关联表字段
    column2='p_id', # 关联记录关联表字段
    string='Authors') # string标签文本
  
    

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)

"""

在创建抽象模型时,many-to-many中不要使用column1和column2属性。在 ORM 设计中对抽象模型有一个限制,如果指定关联表列名,就无法再被正常继承。
 

odoo 关系字段(关联关系)的更多相关文章

  1. (原创)odoo关系字段在视图中的行为控制 总结

    字段类型 选项或属性 格式示例 描述 many2one , many2many_tags(widget) no_create options='{"no_create":True} ...

  2. odoo Model字段的参数

    odoo Model字段的参数 class Field(object): """ The field descriptor contains the field defi ...

  3. Python之关系字段

    参考:https://blog.csdn.net/pugongying1988/article/details/72870264 关系字段:一对一,多对一,多对多 一对一:  现在有很多一对一辅导班, ...

  4. odoo 的字段。orm对象

    OpenERP ORM 对象方法列表   OpenERP对象支持的字段类型有,基础类型:char, text, boolean, integer, float, date, time, datetim ...

  5. Django框架之第六篇(模型层)--单表查询和必知必会13条、单表查询之双下划线、Django ORM常用字段和参数、关系字段

    单表查询 补充一个知识点:在models.py建表是 create_time = models.DateField() 关键字参数: 1.auto_now:每次操作数据,都会自动刷新当前操作的时间 2 ...

  6. python 之 Django框架(ORM常用字段和字段参数、关系字段和和字段参数)

    12.324 Django ORM常用字段 .id = models.AutoField(primary_key=True):int自增列,必须填入参数 primary_key=True.当model ...

  7. 06 ORM常用字段 关系字段 数据库优化查询

    一.Django ORM 常用字段和参数 1.常用字段 models中所有的字段类型其实本质就那几种,整形varchar什么的,都没有实际的约束作用,虽然在models中没有任何限制作用,但是还是要分 ...

  8. django--orm关系字段(ForeignKey、OneToOneField、ManyToManyField)详解

    django中的关系字段 1.ForeignKey字段,即外键字段,对应一对多的情况,列如:一本书对应一个出版社,一个出版社可对应多本书. 2.ManyToManyFiled字段,即多对多字段,对应数 ...

  9. Django:ORM关系字段

    一,ForeignKey 外键类型在ORM中用来表示外键关联关系,一般把ForeignKey字段设置在 '一对多'中'多'的一方. ForeignKey可以和其他表做关联关系同时也可以和自身做关联关系 ...

随机推荐

  1. 一百一十三:CMS系统之前台注册界面

    html {% from 'common/_macros.html' import static %}<!DOCTYPE html><html lang="en" ...

  2. Kubernetes Dashboard的安装与坑【h】

    1.前言 https://github.com/kubernetes/dashboard/releases kubectl apply -f https://raw.githubusercontent ...

  3. Mrchen测试人生

    auto:chenyq date:20190920 data:今天是我从事10年IT软件测试工作来的 开始写技术博客的第一次,希望今后能给互联网需要查询技术知识带来方便: 说起我的测试人生 路也走了1 ...

  4. Django-DRF(视图相关)

    drf除了在数据序列化部分简写代码以外,还在视图中提供了简写操作.所以在django原有的django.views.View类基础上,drf封装了多个子类出来提供给我们使用. Django REST ...

  5. 【图像处理】H.264有四种画质级别

    H.264有四种画质级别,分别是BP.EP.MP.HP,想要说明H.264 HP与H.264 MP的区别就要讲到H.264的技术发展了 H.264 视频编码技术在视频采集.后期制作等网络视频服务领域的 ...

  6. 上传下载文件到Linux服务器

    转自链接:https://blog.csdn.net/drdongshiye/article/details/89430535Mac的终端是十分强大 , 可以通过命令进行上传下载下载文件夹 scp - ...

  7. #内存不够,swap来凑# Linux上创建SWAP文件/分区

    转自:https://www.vmvps.com/how-to-create-a-swap-file-on-the-linux-os.html 很久很久以前,电脑的内存是个珍贵东西,于是乎就有了swa ...

  8. AD域环境取消密码复杂度和密码使用期限

    本地组策略功能中设置密码永不过期的时候发现功能置灰了,不能设置: 这是因为创建域后默认本地组策略功能会被转移到域组策略管理里面,所以我们可以去组策略管理器里去更改组策略,因为一般本地策略的优先级别最低 ...

  9. [转帖]PKI技术原理(收集 整理 归纳)

    PKI技术原理(收集 整理 归纳) https://blog.51cto.com/3layer/20430 总结归纳的 灰常好.. 7layer关注8人评论39427人阅读2007-03-14 11: ...

  10. sql server凭据

    转自:https://blog.csdn.net/kk185800961/article/details/52469170 凭据是包含连接到 SQL Server 外部资源所需的身份验证信息(凭据)的 ...