Yeah, that's expected behavior.
settings = SomeModel.objects.all()
for e in settings:
print e.pk
for e in settings:
print e.pk
for e in settings:
print e.pk
In the above, the database will be hit only once but......
for e in SomeModel.objects.all():
print e.pk
for e in SomeModel.objects.all():
print e.pk
for e in SomeModel.objects.all():
print e.pk
....the database will be hit three times
Sent from my Windows Phone
settings = SomeModel.objects.all()
for e in settings:
print e.pk
for e in settings:
print e.pk
for e in settings:
print e.pk
In the above, the database will be hit only once but......
for e in SomeModel.objects.all():
print e.pk
for e in SomeModel.objects.all():
print e.pk
for e in SomeModel.objects.all():
print e.pk
....the database will be hit three times
Sent from my Windows Phone
From: Venkatraman S
Sent: 3/28/2013 3:51 AM
To: django-users@googlegroups.com
Subject: No multiple calls while iterating the queryset in template
No comments:
Post a Comment