code: def sort_query(self, query, sort_info):
          for sort_opt in sort_info:
              field = sort_opt['field']
              if not hasattr(self.model, field):
                  raise InvalidSort("{} has no attribute {}".format(self.model.__name__, field))
              query = query.order_by(getattr(getattr(self.model, field), sort_opt['order'])())
          return query