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


Python Comment.post方法代码示例

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


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

示例1: manage_comment

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import post [as 别名]
def manage_comment(request):
    if request.method == 'GET':
        if request.GET['action'] == 'delete':
            comment = Comment.objects.get(pk=request.GET['comment_id'])
            comment.delete()
        elif request.GET['action'] == 'edit':
            comment = Comment.objects.get(pk=request.GET['comment_id'])
            comment.text = request.GET['edited_text']
            comment.save()
        elif request.GET['action'] == 'add':
            comment = Comment()
            comment.text = request.GET['text']
            comment.user = request.user
            comment.post = Post.objects.get(pk=request.GET['post_id'])
            comment.save()

            resp = serialize('json', [comment, ])
            resp_obj = json.loads(resp)
            resp_obj[0]['fields']['first_name'] = request.user.first_name
            resp_obj[0]['fields']['last_name'] = request.user.last_name
            resp_obj[0]['fields']['username'] = request.user.username
            return HttpResponse(json.dumps(resp_obj))

        return HttpResponse()
开发者ID:svvorf,项目名称:Otu,代码行数:26,代码来源:views.py

示例2: Post

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import post [as 别名]
    print post_user

    db_post = Post(description=post["description"], creation_date=datetime.datetime.now(), user=post_user, picture=None)

    picture_path = "post_pictures/%s" % path_leaf(post["picture"])

    post_picture = open("instagram/media/" + picture_path, "r")

    db_post.picture.save(picture_path, File(post_picture))

    db_post.save()

    likes = post["likes"]
    for like in likes:
        db_like = Like()
        db_like.user = InstagramUser.objects.filter(username=like)[0]
        db_like.post = db_post
        db_like.save()

    comments = post["comments"]
    for comment in comments:
        comment_user = InstagramUser.objects.filter(username=comment["user"])[0]
        db_comment = Comment()
        db_comment.comment = comment["comment"]
        db_comment.creation_date = datetime.datetime.now()
        db_comment.user = comment_user
        db_comment.post = db_post
        db_comment.save()

posts_file.close()
开发者ID:james9909,项目名称:HSF-2015,代码行数:32,代码来源:create_posts.py


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