// view for update object func (this *CommentAdminEdit) Post() { form := post.CommentAdminForm{} if this.ValidFormSets(&form) == false { return } // get changed field names changes := utils.FormChanges(&this.object, &form) url := fmt.Sprintf("/admin/comment/%d", this.object.Id) // update changed fields only if len(changes) > 0 { form.SetToComment(&this.object) if err := models.UpdateById(this.object.Id, this.object, models.Obj2Table(changes)...); err == nil { this.FlashRedirect(url, 302, "UpdateSuccess") return } else { log.Error(err) this.Data["Error"] = err } } else { this.Redirect(url, 302) } }
// view for new object save func (this *CommentAdminNew) Post() { form := post.CommentAdminForm{Create: true} if this.ValidFormSets(&form) == false { return } var comment models.Comment form.SetToComment(&comment) if err := models.Insert(&comment); err == nil { this.FlashRedirect(fmt.Sprintf("/admin/comment/%d", comment.Id), 302, "CreateSuccess") return } else { log.Error(err) this.Data["Error"] = err } }