当前位置: 首页>>代码示例>>Python>>正文


Python Comment.find方法代码示例

本文整理汇总了Python中models.comment.Comment.find方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.find方法的具体用法?Python Comment.find怎么用?Python Comment.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.comment.Comment的用法示例。


在下文中一共展示了Comment.find方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PostModel

# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import find [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()
开发者ID:christi1001dx,项目名称:proj1-7,代码行数:35,代码来源:post.py

示例2: UserModel

# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import find [as 别名]
class UserModel(Model):

    def __init__(self, db, collection, obj):
        super(UserModel, self).__init__(db, collection, obj)
        self.username = obj['username']
        self.password = obj['password']
        self.voted = obj['voted']
        self.posts = Post()
        self.comments = Comment()

    # Change password with authentication--username auth to be done 
    # in middleware
    def change_password(self, oldpass, newpass):
        if oldpass == self.password:
            self.password = newpass
            self.collection.update({'_id': self.get_id()}, password=newpass)
            return True
        return False

    # Vote a post up, cannot do this more than once for any given post
    def vote_up(self, post_id):
        if not post_id in self.voted:
            p = self.posts.find_one(_id=post_id)
            p.vote_up()
            self.voted.append(post_id)
            self.collection.update({'_id': self.get_id()}, voted=self.voted)

    # Adds a post under the users page
    def add_post(self, **kwargs):
        return self.posts.insert(user=self.username, **kwargs)

    # Get blog posts made by this user, and with other arguments
    def get_posts(self, **kwargs):
        return self.posts.find(user=self.username, **kwargs)

    # Get comments made by the user, with other parameters
    def get_comments(self, **kwargs):
        return self.comments.find(user=self.username, **kwargs)
开发者ID:christi1001dx,项目名称:proj1-7,代码行数:40,代码来源:user.py

示例3: get_comments

# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import find [as 别名]
 def get_comments(self, **kwargs):
     comments = Comment()
     return comments.find(img_id=self.get_id(), **kwargs)
开发者ID:aleung013,项目名称:DWAI,代码行数:5,代码来源:image.py


注:本文中的models.comment.Comment.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。