comment.py 文件源码

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

项目:popcorn-backend 作者: We-Lab 项目源码 文件源码
def perform_create(self, serializer):
        """
        1. ?? ???? ??
        2. ?? ??? ?? ??? ???? movie ??? ??
        3. ?? 1?? 1? ??? ?? ??
        """
        movie = Movie.objects.get(pk=self.kwargs['pk'])
        author = MyUser.objects.get(pk=self.request.user.pk)

        # ?? ???
        try:
            content = self.request.data['content']
            r = ProfanitiesFilter()
            clean_content = r.clean(content)
        except:
            clean_content = ''

        if Comment.objects.filter(movie=movie, author=author).exists():
            raise NotAcceptable('?? ???? ??????')
        serializer.save(movie=movie, author=author, content=clean_content)

        # ?? ?? ??
        movie.comment_count += 1
        new_star = float(self.request.data['star'])
        movie.star_sum += new_star
        movie.star_average = (movie.star_average * (movie.comment_count - 1) + new_star) / movie.comment_count
        movie.save()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号