#NEWLINE# @ classmethod #NEWLINE# def _iterable_order_by( cls , iterable , order_by ) : #NEWLINE# #INDENT# "Sort iterable by field names in order_by\n\n        :param iterable: model objects collection\n        :param order_by: tuple of model fields names for sorting.\n        If name starts with '-' desc ordering applies, else asc.\n        " #NEWLINE# order_by_fields = [ ] #NEWLINE# for field_name in order_by_fields : #NEWLINE# #INDENT# if field_name . startswith ( '-' ) : #NEWLINE# #INDENT# order_by_fields . append ( { #NEWLINE# #INDENT# 'name' : field_name . lstrip ( '-' ) , #NEWLINE# 'lt' : 1 , #NEWLINE# 'gt' : ( - 1 ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# order_by_fields . append ( { #NEWLINE# #INDENT# 'name' : field_name , #NEWLINE# 'lt' : ( - 1 ) , #NEWLINE# 'gt' : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# key = functools . cmp_to_key ( functools . partial ( cls . single . compare , order_by = order_by_fields ) ) #NEWLINE# return sorted ( iterable , key = key )