@kieko

TypeError: 'QuerySet' object is not callable??

total_comments = Comment.objects.filter(movie_id=object_id)().count()
TypeError: 'QuerySet' object is not callable

В чем именно ошибка??

class MoviesTop(APIView):

    def get(self, request):

        if 'start_date' in request.data and 'end_date' in request.data:
            start_timestamp = request.data['start_date']
            end_timestamp = request.data['end_date']
            topMovie = Movie.objects.annotate(
                num_comments=Count(
                    'Comments',
                    filter=Q(Comments__pub_date__range=(
                        start_timestamp, end_timestamp))
                )
                ).order_by('-num_comments')
            serializer = MoviesTopFrameSerializator(topMovie,context = {'start_timestamp':start_timestamp,'end_timestamp':end_timestamp},many = True)
           
        else:
            
            topMovie=Movie.objects.annotate(
                num_comments=Count('Comments')).order_by('-num_comments')
            
            serializer=MoviesTopSerializator(topMovie, many=True)
        
        return Response(serializer.data)


serializator:

class MoviesTopSerializator(serializers.ModelSerializer):

    id_movie = serializers.IntegerField(source='id')
    comment_count = serializers.SerializerMethodField('get_count_comment')
    

    class Meta:
        model = Movie
        fields = ['id_movie', 'comment_count' ]

    def get_count_comment(self, object_id):
        total_comments = Comment.objects.filter(movie_id=object_id)().count()
        return total_comments
  • Вопрос задан
  • 563 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы