本文整理汇总了Python中models.Comment.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.to_dict方法的具体用法?Python Comment.to_dict怎么用?Python Comment.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.to_dict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_create_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import to_dict [as 别名]
def api_create_comment(id):
cookie_str = request.cookies.get(COOKIE_NAME)
user = {}
if cookie_str:
user = cookie2user(cookie_str)
if user is None:
r=jsonify({'error':'Please signin first'})
r.content_type = 'application/json'
return r
if not request.json['content'] or not request.json['content'].strip():
r=jsonify({'error':'no content'})
r.content_type = 'application/json'
return r
blog = Blog.query.filter(Blog.id==id).first()
reprint = Reprint.query.filter(Reprint.id==id).first()
b_id = ''
if blog is not None:
b_id = blog.id
if reprint is not None:
b_id = reprint.id
if not b_id:
r = jsonify({'error':'no blog'})
r.content_type = 'application/json'
return r
comment = Comment(blog_id=b_id, user_id=user.id, user_name=user.name, user_image=user.image, content=request.json['content'].strip())
db.session.add(comment)
db.session.commit()
a = comment.to_dict()
r = jsonify(a)
r.content_type = 'application/json;charset=utf-8'
return r
示例2: _post_new
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import to_dict [as 别名]
def _post_new(self, user, *args):
""" Record a new comment. """
try:
comment = self.get_argument("comment")
title = self.get_argument("title")
now = datetime.datetime.now()
comment = Comment(user=user, title=title, comment=comment,
created=now, updated=now, last_response=now)
self.db.add(comment)
self.db.commit()
return json.dumps({"NewThread": comment.to_dict()})
except Exception as e:
print(e)
pass