Suppose i have :
models.py:
class Books(models.Model):
title = models.CharField(max_length = 200)
author = models.CharField(max_length = 200)
price = models.CharField(max_length = 200)
and in manage.py shell :
# hits the database
>>> book_one = Books.objects.get(id = 1)
# hits the database
>>> foo = book_one.title
u'Foo book'
assuming on the code above, if i type book_one.author we're gonna hit the database again.
By using select_related() if i type book_one.title or book_one.author or book_one.price we're not gonna hit the database again, only when we instance it.
If i type books = Books.objects.all() in manage.py shell and let's say i want to store its specific value (let's say i only want to store title and author field) in an empty list using for loop like :
empty_list = []
for book in books:
empty_list.append([book.title, book.author])
# only 1 data, so we're gonna loop only once
So the question is : based on that loop above, how many times we're gonna hit the database? Is it 2 times because we pass book.title and book.author or only once