[Answered ]-Prefetch not working for ForeignKey's related_name? (Results in n + 2 queries)

1👍

Ah, never mind. I was actually ordering my books in my Serializer method which was adding the additional queries:

  def get_books(self, obj):
    qs = obj.books.order_by(XXX)
    return BookSerializer(qs, many=True).data

If I remove that ordering, it is indeed just two queries.

👤Chris

Leave a comment