django select_related und prefetch_related
* django select_related and prefetch_related
* Prefetch_related and select_related functions in django
---------------------------------
select_related() “follows” foreign-key relationships,
selecting additional related-object data when it executes its query.
prefetch_related() does a separate lookup for each relationship,
and does the “joining” in Python.
-------------------
Example
class A(models.Model):
pass
class B(models.Model):
a = ForeignKey(ModelA)
# Forward ForeignKey relationship
A.objects.select_related('a').all()
# Reverse ForeignKey relationship
A.objects.prefetch_related('modelb_set').all()
ASHABB