在Odoo 8 ORM api中,如何使用search()以相反的顺序获得结果?

时间:2021-01-19 08:33:32

I try to use search() to fetch data from a table in a http controller.

我尝试使用search()从http控制器中的表中获取数据。

 x = obj.search(cr, uid, criteria, offset=0,limit=36,order=sortBy)

It returns an array containing the ids of the top 36 items ordered by sortBy but always in increasing order. But how to make it using decreasing order?

它返回一个数组,其中包含sortBy排序的前36项的ID,但总是按递增顺序排列。但是如何使用递减顺序?

1 个解决方案

#1


12  

Search

搜索

Takes a search domain, returns a recordset of matching records. Can return a subset of matching records (offset and limit parameters) and be ordered (order parameter):

采用搜索域,返回匹配记录的记录集。可以返回匹配记录的子集(偏移和限制参数)并进行排序(顺序参数):

Syntax:

句法:

search(args[, offset=0][, limit=None][, order=None][, count=False])

Parameters:

参数:

  • args -- A search domain. Use an empty list to match all records.
  • args - 搜索域。使用空列表匹配所有记录。
  • offset (int) -- number of results to ignore (default: none)
  • offset(int) - 要忽略的结果数(默认值:无)
  • limit (int) -- maximum number of records to return (default: all)
  • limit(int) - 要返回的最大记录数(默认值:全部)
  • order (str) -- sort string
  • order(str) - 排序字符串
  • count (bool) -- if True, only counts and returns the number of matching records (default: False)
  • count(bool) - 如果为True,则只计算并返回匹配记录的数量(默认值:False)

Returns: Returns records matching the search criteria up to limit.

返回:返回与搜索条件匹配的记录,最多为limit。

Raise AccessError: if user tries to bypass access rules for read on the requested object.

提升AccessError:如果用户试图绕过访问规则以读取请求的对象。

You just need to search in following manner with descending order.

您只需按以下方式按降序搜索。

    sortBy = "field_name desc"
     x = obj.search(cr, uid, criteria, offset=0,limit=36,order=sortBy)

    ###Or you can define directly
     x = obj.search(cr, uid, criteria, offset=0,limit=36,order='field_name desc')

#1


12  

Search

搜索

Takes a search domain, returns a recordset of matching records. Can return a subset of matching records (offset and limit parameters) and be ordered (order parameter):

采用搜索域,返回匹配记录的记录集。可以返回匹配记录的子集(偏移和限制参数)并进行排序(顺序参数):

Syntax:

句法:

search(args[, offset=0][, limit=None][, order=None][, count=False])

Parameters:

参数:

  • args -- A search domain. Use an empty list to match all records.
  • args - 搜索域。使用空列表匹配所有记录。
  • offset (int) -- number of results to ignore (default: none)
  • offset(int) - 要忽略的结果数(默认值:无)
  • limit (int) -- maximum number of records to return (default: all)
  • limit(int) - 要返回的最大记录数(默认值:全部)
  • order (str) -- sort string
  • order(str) - 排序字符串
  • count (bool) -- if True, only counts and returns the number of matching records (default: False)
  • count(bool) - 如果为True,则只计算并返回匹配记录的数量(默认值:False)

Returns: Returns records matching the search criteria up to limit.

返回:返回与搜索条件匹配的记录,最多为limit。

Raise AccessError: if user tries to bypass access rules for read on the requested object.

提升AccessError:如果用户试图绕过访问规则以读取请求的对象。

You just need to search in following manner with descending order.

您只需按以下方式按降序搜索。

    sortBy = "field_name desc"
     x = obj.search(cr, uid, criteria, offset=0,limit=36,order=sortBy)

    ###Or you can define directly
     x = obj.search(cr, uid, criteria, offset=0,limit=36,order='field_name desc')