Django : select_related with ManyToManyField Django : select_related with ManyToManyField django django

Django : select_related with ManyToManyField


Django versions 1.4 and above have prefetch_related for this purpose.

The prefetch_related method is similar to select_related, but does not do a database join. Instead, it executes additional database queries and does the joining in Python.


If you're not on Django 1.4, there's also the django-batch-select library, which works basically the same way as prefetch_related.