[Django]-Can I use select_related() with ManyToManyField on Django Models?

44👍

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.

3👍

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.

👤Shane

Leave a comment