nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:request; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, if_statement; 12, return_statement; 13, identifier:reverse; 14, False; 15, comment:"""Sort current collection."""; 16, assignment; 17, not_operator; 18, block; 19, identifier:reverse; 20, block; 21, call; 22, identifier:field; 23, call; 24, identifier:field; 25, return_statement; 26, expression_statement; 27, attribute; 28, argument_list; 29, attribute; 30, argument_list; 31, attribute; 32, assignment; 33, attribute; 34, identifier:order_by; 35, identifier:field; 36, attribute; 37, identifier:get; 38, attribute; 39, identifier:self; 40, identifier:collection; 41, identifier:field; 42, call; 43, identifier:self; 44, identifier:collection; 45, attribute; 46, identifier:fields; 47, identifier:self; 48, identifier:columns_sort; 49, attribute; 50, argument_list; 51, attribute; 52, identifier:_meta; 53, identifier:field; 54, identifier:desc; 55, identifier:self; 56, identifier:model
code: def sort(self, request, reverse=False):
          """Sort current collection."""
          field = self.model._meta.fields.get(self.columns_sort)
          if not field:
              return self.collection
  
          if reverse:
              field = field.desc()
  
          return self.collection.order_by(field)