本文整理汇总了Golang中github.com/beego/wetalk/modules/models.Post.Update方法的典型用法代码示例。如果您正苦于以下问题:Golang Post.Update方法的具体用法?Golang Post.Update怎么用?Golang Post.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/beego/wetalk/modules/models.Post
的用法示例。
在下文中一共展示了Post.Update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdatePost
func (form *PostForm) UpdatePost(post *models.Post, user *models.User) error {
changes := utils.FormChanges(post, form)
if len(changes) == 0 {
return nil
}
utils.SetFormValues(form, post)
post.Category.Id = form.Category
post.Topic.Id = form.Topic
for _, c := range changes {
if c == "Content" {
post.ContentCache = utils.RenderMarkdown(form.Content)
changes = append(changes, "ContentCache")
}
}
// update last edit author
if post.LastAuthor != nil && post.LastAuthor.Id != user.Id {
post.LastAuthor = user
changes = append(changes, "LastAuthor")
}
changes = append(changes, "Updated")
return post.Update(changes...)
}
示例2: PostReplysCount
func PostReplysCount(post *models.Post) {
cnt, err := post.Comments().Count()
if err == nil {
post.Replys = int(cnt)
err = post.Update("Replys")
}
if err != nil {
beego.Error("PostReplysCount ", err)
}
}
示例3: PostReplysCount
func PostReplysCount(post *models.Post) {
cnt, err := post.Comments().Count()
if err == nil {
post.Replys = int(cnt)
//disable post editable
post.CanEdit = false
err = post.Update("Replys", "CanEdit")
}
if err != nil {
beego.Error("PostReplysCount ", err)
}
}
示例4: SaveComment
func (form *CommentForm) SaveComment(comment *models.Comment, user *models.User, post *models.Post) error {
comment.Message = form.Message
comment.MessageCache = utils.RenderMarkdown(form.Message)
comment.User = user
comment.Post = post
if err := comment.Insert(); err == nil {
post.LastReply = user
post.Update("LastReply", "Updated")
cnt, _ := post.Comments().Filter("Id__lte", comment.Id).Count()
comment.Floor = int(cnt)
return comment.Update("Floor")
} else {
return err
}
}
示例5: Post
func (this *ApiRouter) Post() {
if this.CheckActiveRedirect() {
return
}
if this.IsAjax() {
result := map[string]interface{}{
"success": false,
}
action := this.GetString("action")
switch action {
case "toggle-best":
if !this.User.IsAdmin {
result["success"] = false
} else {
if postId, err := this.GetInt("post"); err == nil {
//set post best
var post models.Post
if err := orm.NewOrm().QueryTable("post").Filter("Id", postId).One(&post); err == nil {
post.IsBest = !post.IsBest
if post.Update("IsBest") == nil {
result["success"] = true
}
}
}
}
case "toggle-fav":
if postId, err := this.GetInt("post"); err == nil {
var post models.Post
if err := orm.NewOrm().QueryTable("post").Filter("Id", postId).One(&post); err == nil {
if post.Id != 0 {
var favoritePost models.FavoritePost
if this.User.FavoritePosts().Filter("Post__id", post.Id).One(&favoritePost); err == nil {
if favoritePost.Id > 0 {
//toogle IsFav
favoritePost.IsFav = !favoritePost.IsFav
if favoritePost.Update("IsFav") == nil {
//update user fav post count
if favoritePost.IsFav {
this.User.FavPosts += 1
} else {
this.User.FavPosts -= 1
}
if this.User.Update("FavPosts") == nil {
result["success"] = true
}
}
} else {
favoritePost = models.FavoritePost{
User: &this.User,
Post: &post,
IsFav: true,
}
if favoritePost.Insert() == nil {
//update user fav post count
this.User.FavPosts += 1
if this.User.Update("FavPosts") == nil {
result["success"] = true
}
}
}
}
}
}
}
}
this.Data["json"] = result
this.ServeJson()
}
}