def save(self, commit=True, **kwargs):
    if not self.is_valid:
      raise ValueError('Cannot save a non valid form')
    opts = self._meta
    instance = self.instance
    if instance is None:
      fail_message = 'created'
    else:
      fail_message = 'updated'
    if self.errors:
      raise ValueError("The %s could not be %s because the data didn't "
                       'validate.' % (opts.model.kind(), fail_message))
    cleaned_data = self.data
    converted_data = {}
    propiter = itertools.chain(
      opts.model.properties().iteritems(),
      iter([('key_name', StringProperty(name='key_name'))])
    )
    for name, prop in propiter:
      if cleaned_data.has_key(name):
        value = cleaned_data.get(name)
        if not value and prop.default is not None:
          value = prop.default
        converted_data[name] = prop.make_value_from_form(value)
    try:
      converted_data.update(kwargs)
      if instance is None:
        if issubclass(opts.model, NamedModel):
          logging.debug("commit argument ignored.")
          instance = opts.model.create_new_entity(**converted_data)
        else:
          instance = opts.model(**converted_data)
        self.instance = instance
      else:
        for name, value in converted_data.iteritems():
          if name == 'key_name':
            continue
          setattr(instance, name, value)
    except db.BadValueError, err:
      raise ValueError('The %s could not be %s (%s)' %
                       (opts.model.kind(), fail_message, err))
    if commit:
      instance.put()
    return instance
Save this form's cleaned data into a model instance.
dataset/ETHPy150Open IanLewis/kay/kay/utils/forms/modelform.py/BaseModelForm.save