本文整理汇总了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()
示例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()