本文整理汇总了Golang中github.com/royburns/roysblog/models.Post.Query方法的典型用法代码示例。如果您正苦于以下问题:Golang Post.Query方法的具体用法?Golang Post.Query怎么用?Golang Post.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/royburns/roysblog/models.Post
的用法示例。
在下文中一共展示了Post.Query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: List
//管理
func (this *ArticleController) List() {
var (
page int64
pagesize int64 = 10
status int64
offset int64
list []*models.Post
post models.Post
searchtype string
keyword string
)
searchtype = this.GetString("searchtype")
keyword = this.GetString("keyword")
status, _ = this.GetInt64("status")
if page, _ = this.GetInt64("page"); page < 1 {
page = 1
}
offset = (page - 1) * pagesize
query := post.Query().Filter("status", status)
if keyword != "" {
switch searchtype {
case "title":
query = query.Filter("title__icontains", keyword)
case "author":
query = query.Filter("author__icontains", keyword)
case "tag":
query = query.Filter("tags__icontains", keyword)
}
}
count, _ := query.Count()
if count > 0 {
query.OrderBy("-istop", "-posttime").Limit(pagesize, offset).All(&list)
}
this.Data["searchtype"] = searchtype
this.Data["keyword"] = keyword
this.Data["count_1"], _ = post.Query().Filter("status", 1).Count()
this.Data["count_2"], _ = post.Query().Filter("status", 2).Count()
this.Data["status"] = status
this.Data["list"] = list
this.Data["pagebar"] = models.NewPager(page, count, pagesize, fmt.Sprintf("/admin/article/list?status=%d&searchtype=%s&keyword=%s&page=%s", status, searchtype, keyword, "%d")).ToString()
this.display()
}
示例2: Batch
//批处理
func (this *ArticleController) Batch() {
ids := this.GetStrings("ids[]")
op := this.GetString("op")
idarr := make([]int64, 0)
for _, v := range ids {
if id, _ := strconv.Atoi(v); id > 0 {
idarr = append(idarr, int64(id))
}
}
var post models.Post
switch op {
case "topub": //移到已发布
post.Query().Filter("id__in", idarr).Update(orm.Params{"status": 0})
case "todrafts": //移到草稿箱
post.Query().Filter("id__in", idarr).Update(orm.Params{"status": 1})
case "totrash": //移到回收站
post.Query().Filter("id__in", idarr).Update(orm.Params{"status": 2})
case "delete": //批量删除
for _, id := range idarr {
obj := models.Post{Id: id}
if obj.Read() == nil {
obj.Delete()
}
}
}
this.Redirect(this.Ctx.Request.Referer(), 302)
}