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.
- [Django]-Django admin page Removing 'Group'
- [Django]-How can I serialize a queryset from an unrelated model as a nested serializer?
- [Django]-Django check if a related object exists error: RelatedObjectDoesNotExist
Source:stackexchange.com