code: def _generate_comparator(cls, field_names):
          field_names = list(field_names)
          reverses = [1] * len(field_names)
          for i, field_name in enumerate(field_names):
              if field_name[0] == '-':
                  reverses[i] = -1
                  field_names[i] = field_name[1:]
          field_names = [f.replace(LOOKUP_SEP, '.') for f in field_names]
          def comparator(i1, i2):
              v1 = attrgetter(*field_names)(i1)
              v2 = attrgetter(*field_names)(i2)
              if len(field_names) == 1:
                  return cls._cmp(v1, v2) * reverses[0]
              order = multiply_iterables(list(map(cls._cmp, v1, v2)), reverses)
              try:
                  return next(dropwhile(__not__, order))
              except StopIteration:
                  return 0
          return comparator