code: def sort(self, *sort_tuples):
          ''' pymongo-style sorting.  Accepts a list of tuples.
              :param sort_tuples: varargs of sort tuples.
          '''
          query = self
          for name, direction in sort_tuples:
              field = resolve_name(self.type, name)
              if direction in (ASCENDING, 1):
                  query = query.ascending(field)
              elif direction in (DESCENDING, -1):
                  query = query.descending(field)
              else:
                  raise BadQueryException('Bad sort direction: %s' % direction)
          return query