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系统之cms用户模型定义

    数据库信息 DEBUG = TrueSQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:123456@127.0.0.1:3306/test'SQLALCH ...

  2. 编解码原理,Python默认解码是ascii

    编解码原理,Python默认解码是ascii 首先我们知道,python里的字符默认是ascii码,英文当然没问题啦,碰到中文的时候立马给跪. 不知道你还记不记得,python里打印中文汉字的时候需要 ...

  3. java文件上传系统

    我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用. 首先我们需要了解的是上传文件三要素: 1.表单提交方式:post (get方式提交有大小 ...

  4. Pytorch-tensor的维度变化

    引言 本篇介绍tensor的维度变化. 维度变化改变的是数据的理解方式! view/reshape:大小不变的条件下,转变shape squeeze/unsqueeze:减少/增加维度 transpo ...

  5. 树莓派-CentOS-Minimal arm版的设置

    将镜像用 balenaEtcher 写入到树莓派SD卡并启动后,需要对其进行一些设置才能正常使用. 1. 用户名 root 密码 centos 2. 扩展 rootfs 到最大可用空间:cat REA ...

  6. 拷贝docker镜像到其他机器部署

    有拷贝docker images到其他主机的情况,当然是通过pull的方式来转移到其他宿主机. 1 sudo docker save -o golang:alpine3.7  ./my-golang- ...

  7. 重点做EUR/USD、EUR/JPY、GBP/USD。

    这三种货币对,几乎每天都有合适的行情.

  8. 【POJ - 3262】Protecting the Flowers(贪心)

    Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...

  9. VMware一些概念

    物理机:真真实实存在的机器,有操作系统.内存.硬盘.网卡. 虚拟机:vmware虚拟出来的,和物理机一样有操作系统.内存.硬盘.网卡. 虚拟机的网络连接的桥接模式.NAT模式.仅主机模式简单解说:  ...

  10. [图像分割] OpenCV 的 GrabCut 函数使用和源码解读

    转自 zouxy09 GrabCut 原理参考这里,以下为 GrabCut 源码: ——看别人写的好的代码也很享受,干净利落,有些处理的细节也学习一下. /*M//////////////////// ...