nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, dictionary_splat_pattern; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, if_statement; 12, return_statement; 13, identifier:sorting; 14, identifier:kwargs; 15, comment:"""Sort resources."""; 16, assignment; 17, pattern_list; 18, identifier:sorting; 19, block; 20, identifier:sorting_; 21, block; 22, attribute; 23, identifier:sorting_; 24, list; 25, identifier:name; 26, identifier:desc; 27, expression_statement; 28, if_statement; 29, if_statement; 30, expression_statement; 31, return_statement; 32, identifier:self; 33, identifier:collection; 34, assignment; 35, comparison_operator:field is None; 36, block; 37, identifier:desc; 38, block; 39, call; 40, call; 41, identifier:field; 42, call; 43, identifier:field; 44, None; 45, continue_statement; 46, expression_statement; 47, attribute; 48, argument_list; 49, attribute; 50, argument_list; 51, attribute; 52, argument_list; 53, assignment; 54, identifier:sorting_; 55, identifier:append; 56, identifier:field; 57, attribute; 58, identifier:order_by; 59, list_splat; 60, attribute; 61, identifier:get; 62, identifier:name; 63, identifier:field; 64, call; 65, identifier:self; 66, identifier:collection; 67, identifier:sorting_; 68, attribute; 69, identifier:fields; 70, attribute; 71, argument_list; 72, attribute; 73, identifier:_meta; 74, identifier:field; 75, identifier:desc; 76, attribute; 77, identifier:model; 78, identifier:self; 79, identifier:meta
code: def sort(self, *sorting, **kwargs):
          """Sort resources."""
          sorting_ = []
          for name, desc in sorting:
              field = self.meta.model._meta.fields.get(name)
              if field is None:
                  continue
              if desc:
                  field = field.desc()
              sorting_.append(field)
          if sorting_:
              return self.collection.order_by(*sorting_)
          return self.collection