// view for update object func (this *UserAdminEdit) Post() { form := auth.UserAdminForm{Id: int(this.object.Id)} if this.ValidFormSets(&form) == false { return } // get changed field names changes := utils.FormChanges(&this.object, &form) url := fmt.Sprintf("/admin/user/%d", this.object.Id) // update changed fields only if len(changes) > 0 { form.SetToUser(&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 *UserAdminNew) Post() { form := auth.UserAdminForm{Create: true} if this.ValidFormSets(&form) == false { return } var user models.User form.SetToUser(&user) if err := models.Insert(&user); err == nil { this.FlashRedirect(fmt.Sprintf("/admin/user/%d", user.Id), 302, "CreateSuccess") return } else { log.Error(err) this.Data["Error"] = err } }