code: def _resolve_sort_by(sort_by, flag_radius_query):
          if sort_by is None:
              if flag_radius_query:
                  sort_by = SORT_BY_DIST
          elif isinstance(sort_by, string_types):
              if sort_by.lower() == SORT_BY_DIST:
                  if flag_radius_query is False:
                      msg = "`sort_by` arg can be 'dist' only under distance based query!"
                      raise ValueError(msg)
                  sort_by = SORT_BY_DIST
              elif sort_by not in SimpleZipcode.__table__.columns:
                  msg = "`sort_by` arg has to be one of the Zipcode attribute or 'dist'!"
                  raise ValueError(msg)
          else:
              sort_by = sort_by.name
          return sort_by