model = $extra['model']; if (isset($extra['fields'])) { // Only display a subset of the fields $cols = array(); foreach ($extra['fields'] as $field) { $cols[$field] = $this->model->_a['cols'][$field]; } } else { $cols = $this->model->_a['cols']; } foreach ($cols as $name=>$def) { $db_field = new $def['type']('', $name); $defaults = array('blank' => true, 'verbose' => $name, 'help_text' => '', 'editable' => true); $def = array_merge($defaults, $def); if ($def['editable']) { // The 'model_instance' and 'name' are used by the // ManyToMany field. $def['model_instance'] = $this->model; $def['name'] = $name; if (null !== ($form_field=$db_field->formField($def))) { $this->fields[$name] = $form_field; } } } } /** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit=true) { if ($this->isValid()) { $this->model->setFromFormData($this->cleaned_data); if ($commit && $this->model->id) { $this->model->update(); } elseif ($commit) { $this->model->create(); } return $this->model; } throw new Exception(__('Cannot save the model from an invalid form.')); } }