zoukankan      html  css  js  c++  java
  • Odoo Documentation : Recordsets

    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')
  • 相关阅读:
    金额与数字转化常用实用几个JS方法
    Jdb命令 The Java Debugger
    GLOBAL TEMPORARY TABLE
    安装与配置Nginx
    MySQL二进制安装与密码破解
    基于FPM构建企业RPM包
    安装Tomcat
    nginx配置优化
    DHCP原理及配置(三个小实验)
    DNS主、从服务器的配置
  • 原文地址:https://www.cnblogs.com/dancesir/p/7025972.html
Copyright © 2011-2022 走看看