comment.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:popcorn-backend 作者: We-Lab 项目源码 文件源码
def get(self, request, *args, **kwargs):
        box_office = BoxOfficeMovie.objects.all().order_by('-created')[:10]

        # ????? ?? ?? ?? ????
        comments = []
        for i in box_office:
            comment = Comment.objects.filter(movie__pk=i.movie.pk)
            for k in comment:
                comments.append(k)
        # print('???', comments)

        # 5? ??? 1? ?? ??
        comments = sorted(comments, key=attrgetter('likes_count'), reverse=True)
        comments = comments[:5]
        # print('???', comments)
        if len(comments) == 0:
            raise NotAcceptable('???? ????')
        else:
            best_comment = random.sample(comments, 1)

        serializer = CommentSerializer(best_comment, many=True)
        return Response(serializer.data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号