本文整理汇总了Python中models.comment.Comment.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.remove方法的具体用法?Python Comment.remove怎么用?Python Comment.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.comment.Comment
的用法示例。
在下文中一共展示了Comment.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PostModel
# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import remove [as 别名]
class PostModel(Model):
def __init__(self, db, collection, obj):
super(PostModel, self).__init__(db, collection, obj)
self.user = obj['user']
self.title = obj['title']
self.body = obj['body']
self.tags = obj['tags']
self.upvotes = obj['upvotes']
self.comments = Comment()
# Increases the upvotes on a post
def vote_up(self):
self.upvotes += 1
self.collection.objects.update({'_id': self.get_id()},
{'$inc': {'upvotes': 1}})
# Adds a comment on this post
def add_comment(self, **kwargs):
return self.comments.insert(post_id=self.get_id(), **kwargs)
# Gets comments on this post
def get_comments(self):
return self.comments.find(post_id=self.get_id())
# Use for removing comments by the user who created them, or by the poster
def remove_comments(self, **kwargs):
self.comments.remove(**kwargs)
# Removes self and the comments
def remove(self):
self.remove_comments(post_id=self.get_id())
super(PostModel, self).remove()