// view for update object func (this *TopicAdminRouter) Update() { form := post.TopicAdminForm{Id: this.object.Id} if this.ValidFormSets(&form) == false { return } // get changed field names changes := utils.FormChanges(&this.object, &form) url := fmt.Sprintf("/admin/topic/%d", this.object.Id) // update changed fields only if len(changes) > 0 { form.SetToTopic(&this.object) if err := this.object.Update(changes...); err == nil { this.FlashRedirect(url, 302, "UpdateSuccess") return } else { beego.Error(err) this.Data["Error"] = err } } else { this.Redirect(url, 302) } }
// view for new object save func (this *TopicAdminRouter) Save() { form := post.TopicAdminForm{Create: true} if this.ValidFormSets(&form) == false { return } var topic models.Topic form.SetToTopic(&topic) if err := topic.Insert(); err == nil { this.FlashRedirect(fmt.Sprintf("/admin/topic/%d", topic.Id), 302, "CreateSuccess") return } else { beego.Error(err) this.Data["Error"] = err } }
// view for edit object func (this *TopicAdminRouter) Edit() { form := post.TopicAdminForm{} form.SetFromTopic(&this.object) this.SetFormSets(&form) }