I'm have a django query with annotate
and prefetch_related
.
all_questions = Question.objects.all().annotate(is_complete=Case(
When(
pk__in=completed_questions.values('pk'),
then=Value(True)
),
default=Value(False),
output_field=BooleanField()),
votes_difference=Count('like')-Count('unlike'),
).order_by('votes_difference').prefetch_related('tags')
I want to limit the result to, let's say 100 objects.
I tried this query:
all_questions = Question.objects.all().annotate(is_complete=Case(
When(
pk__in=completed_questions.values('pk'),
then=Value(True)
),
default=Value(False),
output_field=BooleanField()),
votes_difference=Count('like')-Count('unlike'),
).order_by('votes_difference')[100].prefetch_related('tags')
I got this error message:
'Question' object has no attribute 'prefetch_related'
I checked the official documentation but can't seem to find any example related to it. Is it possible to do so?