1๐
โ
.prefetch_related(โฆ)
[Django-doc] does not fetches the ModelB
s in the same query, but in a second query where it fetches all the related ModelB
s for the selected (filtered) ModelA
s in bulk, this in contract to fetching it per ModelA
object which would be the usual behavior.
For a DetailView
[Django-doc], it will thus not make any improvement. In a DetailView
you render a single item, and fetching the related ModelB
s will, regardless whether it is done through .prefetch_related(โฆ)
or by accessing object.model_a_related.all()
make one extra query.
Source:stackexchange.com