Дилян Палаузов
unread,Jul 23, 2016, 8:44:39 AM7/23/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Hello,
for the rendering of one View I want to execute two queries:
class A(model.Model):
i = models.CharField(max_length=10)
class B(model.Model):
f = models.ManyToManyField(A, on_delete...)
j = models.CharField(max_length=10)
- All objects of type A
queryset1 = A.objects.all()
- All objects of type B prefetching the related objects of type A:
queryset2 = B.objects.prefetch_related('f')
Under these conditions the table A is SELECTEd twice: once all elements are picked up and the result is cached in queryset1. The second time the columns of table A are touched again, if they stay in relation to B objects.
Is there any way to feed into queryset2 the (prefetched) results from queryset1, so that the second SELECT ... FROM A can be prevented (and the join can still happen python-side in RAM)?
Thanks in advance for your answer
Dilian