# Using search\_order on Many2One

**URL:** <https://discuss.tryton.org/t/using-search-order-on-many2one/1825>\
**Category:** Developer\
**Created:** [October 11, 2019, 1:32pm UTC](https://discuss.tryton.org/t/using-search-order-on-many2one/1825 "2019-10-11T13:32:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)\
**Post date:** [October 11, 2019, 1:32pm UTC](https://discuss.tryton.org/t/using-search-order-on-many2one/1825/1 "2019-10-11T13:32:22Z")

</div>

Hi,  
Need some help how to user search\_order attribute on Many2One field. Don’t find any example in code.  
How to sort on specific field following ascending or descending order ?  
I try to define a descending order on number when searching lot\_number on move:

```auto
class Move(metaclass=PoolMeta):
    __name__ = 'stock.move'

    @classmethod
    def __setup__ (cls):
        super(Move, cls). __setup__ ()
        cls.lot.search_order = [(Eval('number'), 'DESC'),]

```

Thanks!

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [October 11, 2019, 2:09pm UTC](https://discuss.tryton.org/t/using-search-order-on-many2one/1825/2 "2019-10-11T14:09:46Z")

</div>

It is an order like the [`ModelSQL._order`](http://docs.tryton.org/projects/server/en/latest/ref/models/models.html#trytond.model.ModelSQL._order), the only difference is that it can be a PYSON statement that must returns the usual order clause format.  
In your example, it does not generate a valid order clause as `Eval('number')` will be replaced by the value from the record.  
If I understand what you try to achieve you should just use:

```auto
 cls.lot.search_order = [('number', 'DESC')]

```

---

<div class="post-metadata">

**Author:** ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)\
**Post date:** [October 14, 2019, 7:53am UTC](https://discuss.tryton.org/t/using-search-order-on-many2one/1825/3 "2019-10-14T07:53:21Z")

</div>

It’s working. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [November 13, 2019, 7:53am UTC](https://discuss.tryton.org/t/using-search-order-on-many2one/1825/4 "2019-11-13T07:53:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
