Answer the question
In order to leave comments, you need to log in
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)
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
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question