Other recordset operations

Recordsets are iterable(可迭代的) so the usual Python tools are available for transformation (map()sorted()ifilter(), ...) however these return either a list or an iterator, removing the ability(能力) to call methods on their result, or to use set operations.

Recordsets therefore provide these operations returning recordsets themselves (when possible):

filtered()

returns a recordset containing only records satisfying the provided predicate function(判定函数). The predicate can also be a string to filter by a field being true or false:

# only keep records whose company is the current user's
records.filtered(lambda r: r.company_id == user.company_id) # only keep records whose partner is a company
records.filtered("partner_id.is_company")
sorted()

returns a recordset sorted by the provided key function. If no key is provided, use the model's default sort order:

# sort records by name
records.sorted(key=lambda r: r.name)
mapped()

applies the provided function to each record in the recordset, returns a recordset if the results are recordsets:

# returns a list of summing two fields for each record in the set
records.mapped(lambda r: r.field1 + r.field2)

The provided function can be a string to get field values:

# returns a list of names
records.mapped('name') # returns a recordset of partners
record.mapped('partner_id') # returns the union of all partner banks, with duplicates removed
record.mapped('partner_id.bank_ids')

Odoo Documentation : Recordsets的更多相关文章

  1. Odoo Documentation : Environment

    Environment The Environment stores various contextual data(上下文数据 ) used by the ORM: the database cur ...

  2. Odoo Documentation : Fields

    Fields Basic fields class openerp.fields.Field(string=None, **kwargs) The field descriptor contains ...

  3. Defining custom settings in Odoo

    Unfortunately Odoo documentation doesn’t seem to include any information about adding new configurat ...

  4. odoo配置界面设置字段默认值

    转自国外牛人博客:http://ludwiktrammer.github.io/odoo/custom-settings-odoo.html Defining custom settings in O ...

  5. odoo 有哪些文档资源

    // openbook [覆盖 openerp 7 及之前版本] https://doc.odoo.com/     // 最新的 odoo documentation user[覆盖 odoo 9] ...

  6. 【原创】Odoo开发文档学习之:ORM API接口(ORM API)(边Google翻译边学习)

    官方ORM API开发文档:https://www.odoo.com/documentation/10.0/reference/orm.html Recordsets(记录集) New in vers ...

  7. Odoo中的Javascript单元测试

    前端页面利用QUnit进行单元测试,本文参考官方文档:https://www.odoo.com/documentation/8.0/reference/javascript.html 访问/web/t ...

  8. ODOO 源代码安装要求

    ODOO 源代码安装要求 ref:http://www.odoo.com/documentation/10.0/setup/install.html#setup-install-source pyth ...

  9. 配置Windows 2008 R2 64位 Odoo 8.0 源码PyCharm开发调试环境

    安装过程中,需要互联网连接下载python依赖库: 1.安装: Windows Server 2008 R2 x64标准版 2.安装: Python 2.7.10 amd64 到C:\Python27 ...

随机推荐

  1. Mysql 权限命令整理大全

    mysql show slave status 需要什么权限 grant replication client on *.* to 'user_name'@'%';

  2. 【JZOJ3422】水叮当的舞步

    description 水叮当得到了一块五颜六色的格子形地毯作为生日礼物,更加特别的是,地毯上格子的颜色还能随着踩踏而改变. 为了讨好她的偶像虹猫,水叮当决定在地毯上跳一支轻盈的舞来卖萌~~~ 地毯上 ...

  3. 使用ajax怎么请求跨域资源

    1.ajax中添加“xhrFields”和“crossDomain”,如: $.ajax({ url: url, data: data, type: "post", xhrFiel ...

  4. jQuery FormData使用方法

    FormData的主要用途 将form表单元素的name与value进行组合,实现表单数据的序列化,从而减少表单元素的拼接,提高工作效率. 异步上传文件 注:FormData 对象的字段类型可以是 B ...

  5. 单独编译和使用webrtc音频增益模块(附完整源码+测试音频文件)

    webrtc的音频处理模块分为降噪ns和nsx,回音消除aec,回声控制acem,音频增益agc,静音检测部分.另外webrtc已经封装好了一套音频处理模块APM,如果不是有特殊必要,使用者如果要用到 ...

  6. Bootstrap FileInput.js + springmvc uploadFile

    下载FileInput.js          http://plugins.krajee.com/file-input/demo     https://github.com/kartik-v/bo ...

  7. 线性dp——cf1096D

    dp[i][j]表示到第i位,与hard的匹配状态到达了第j位 每位有两种决策:消或者不消 分别转移一下即可 转移代码 ;i<n;++i) ;j<=;++j) { cmin(f[i+][j ...

  8. C++Builder常用函数

    BCB函数集 1.内存分配     函数名称 AllocMem 函数说明 在队中分配指定字节的内存块,并将分配的每一个字节初始化为 0.函数原型如下: void * __fastcall AllocM ...

  9. (转)Android中RelativeLayout各个属性的含义

    转:http://blog.csdn.net/softkexin/article/details/5933589 android:layout_above="@id/xxx"  - ...

  10. HttpUrlConnection使用详解--转AAAAA

    http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpConnection.html HttpUr ...