Files
tryton/trytond/model/order.py
T
Nicolas Évrard c3f69d1db7 Add NULLS ordering
issue5858
review27651002
2017-03-29 23:12:01 +02:00

20 lines
704 B
Python

# This file is part of Tryton. The COPYRIGHT file at the toplevel of this
# repository contains the full copyright notices and license terms.
from trytond.model import fields
def sequence_ordered(field_name='sequence', field_label='Sequence',
order='ASC NULLS FIRST'):
"Returns a mixin to order the model by order fields"
class SequenceOrderedMixin(object):
"Mixin to order model by a sequence field"
@classmethod
def __setup__(cls):
super(SequenceOrderedMixin, cls).__setup__()
cls._order = [(field_name, order)] + cls._order
setattr(SequenceOrderedMixin, field_name, fields.Integer(field_label))
return SequenceOrderedMixin