@course_data.route('/<int:course_id>/douyin',methods=['get'])
def get_douyin(course_id):
# 筛选出课程
course = Course.query.get(course_id)
# CourseComment
# 字典推导式推出当前课程的评论
comments_dict = {comment.id: orm2dict(comment) for comment in course.comment_id}
comments = []
for comment in comments_dict.values():
if not comment['root_id']:
comment['son'] = []
comments. Append(comment)
continue
author = CourseComment.query.get(comment['reply_id']).author
comment['to_user_id'] = author.id
comment['to_user_name'] = author.nikename
comments_dict[comment['root_id']]['son'].append(comment)
return ret_route(data=comments)
实验楼项目,通过课程查出该课程下的评论并展示。