func (this *AdminRouter) ModelGet() { id := this.GetString("id") model := this.GetString("model") result := map[string]interface{}{ "success": false, } var data []orm.ParamsList defer func() { if len(data) > 0 { result["success"] = true result["data"] = data[0] } this.Data["json"] = result this.ServeJson() }() var qs orm.QuerySeter switch model { case "User": qs = models.Users() } qs = qs.Filter("Id", id).Limit(1) switch model { case "User": qs.ValuesList(&data, "Id", "UserName") } }
// 检查结果集是否存在 func CheckIsExist(qs orm.QuerySeter, field string, value interface{}, skipId int) bool { qs = qs.Filter(field, value) if skipId > 0 { qs = qs.Exclude("Id", skipId) } return qs.Exist() }
func (this *PostListRouter) postsFilter(qs orm.QuerySeter) orm.QuerySeter { args := []string{utils.ToStr(this.Locale.Index())} if this.isLogin { args = append(args, this.user.LangAdds...) args = append(args, utils.ToStr(this.user.Lang)) } qs = qs.Filter("Lang__in", args) return qs }