Lookup was already seen with a different queryset. Django

I have a Quotes model referenced by the Comment model, which has a liked field (likes of the Comment model). I am trying to optimize the query so that there is no n+1 error, but this exception occurs. The problem is that I need to pull the user out of Comment and like, but it doesn't come out. How to do it? Table 'user' - it's ForeignKey Table 'liked' - it's ManyToManyField

Views.py

def get(self, request, *args, **kwargs):
        post = Quotes.objects.prefetch_related(
            Prefetch(
                'quotes_comment',
                queryset=Comment.objects.select_related('user'))
        ).prefetch_related(
            Prefetch(
                'quotes_comment', 
                queryset=Comment.objects.select_related('liked')
            )
        )
Back to Top