// view for list model data func (this *TopicAdminRouter) List() { var topics []models.Topic qs := models.Topics().OrderBy("-Category__id").RelatedSel() if err := this.SetObjects(qs, &topics); err != nil { this.Data["Error"] = err beego.Error(err) } }
func (form *TopicAdminForm) Valid(v *validation.Validation) { qs := models.Topics() if models.CheckIsExist(qs, "Name", form.Name, form.Id) { v.SetError("Name", "admin.field_need_unique") } if models.CheckIsExist(qs, "Slug", form.Slug, form.Id) { v.SetError("Slug", "admin.field_need_unique") } }
// view for delete object func (this *CategoryAdminRouter) Delete() { if this.FormOnceNotMatch() { return } // check whether there are topics under the category qs := models.Topics().Filter("Category__Id", this.object.Id) cnt, _ := qs.Count() if cnt > 0 { this.FlashRedirect("/admin/category", 302, "DeleteNotAllowed") return } else { // delete object if err := this.object.Delete(); err == nil { this.FlashRedirect("/admin/category", 302, "DeleteSuccess") return } else { beego.Error(err) this.Data["Error"] = err } } }
func (this *TopicAdminRouter) ObjectQs() orm.QuerySeter { return models.Topics().RelatedSel() }
func ListTopicsOfCategory(topics *[]models.Topic, cat *models.Category) (int64, error) { return models.Topics().Filter("Category__id", cat.Id).OrderBy("-order").All(topics) }
func ListTopics(topics *[]models.Topic) (int64, error) { return models.Topics().OrderBy("-Followers").All(topics) }