1. About select_related():
It is said that it will automatically "follow" foreign-key
relationships, selecting that additional related-object data when it
executes its query. So it is not applicable for ManyToMany
relationship, isn't it?

And if select_related() is used,  will the queryset method on the
related Manager access the DB later? For example:
b = Book.objects.select_related().get(id=4)
p = b.author         # Doesn't hit the database.
p.get(pk=3) # Will this action hit the database?

2.  About iterator(), 'for' and 'enumerate' on queryset:
There is a snippet from the django document page(http://
www.djangoproject.com/documentation/db-api/):
  iterator()
  Evaluates the QuerySet (by performing the query) and returns an
iterator over the results. .......
  Note that using iterator() on a QuerySet which has already been
evaluated will force it to evaluate again, repeating the query.

And I found the following document of python on iterater and
enumarate:
iterater http://www.python.org/dev/peps/pep-0234/
    This document proposes an iteration interface that objects can
    provide to control the behaviour of 'for' loops.
enumerate() http://www.python.org/dev/peps/pep-0279/
    It provides all iterable collections with the same advantage that
iteritems() affords to
    dictionaries -- a compact, readable, reliable index notation.

It seems that 'for' loop and enumerate on a QuerySet will use its
iterator. Then if I use 'for' loop or enumerate() on a queryset to do
some logical task and in the template it will iterate the QuerySet
again to display all the data, will the database be hit again?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to