def _coerce_to_key(value):
  if value is None:
    return None

  value, multiple = datastore.NormalizeAndTypeCheck(
    value, (Model, Key, basestring))

  if len(value) > 1:
    raise datastore_errors.BadArgumentError('Expected only one model or key')
  value = value[0]

  if isinstance(value, Model):
    return value.key()
  elif isinstance(value, basestring):
    return Key(value)
  else:
    return value
Returns the value's key.
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/ext/db/__init__.py/_coerce_to_key