I have person
table as shown below:
# "store/models.py"
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=30)
And, I have test
view with print(Person.objects.all())
as shown below:
# "store/views.py"
from django.http import HttpResponse
from .models import Person
def test(request):
print(Person.objects.all()) # Here
return HttpResponse("Test")
Then, when I run test
view, SELECT
query is run as shown below. *I used PostgreSQL and these logs below are the query logs of PostgreSQL. You can check On PostgreSQL, how to log SQL queries with transaction queries such as "BEGIN" and "COMMIT":
Now, I replace print(Person.objects.all())
with Person.objects.all()
as shown below:
# "store/views.py"
from django.http import HttpResponse
from .models import Person
def test(request):
Person.objects.all() # Here
# print(Person.objects.all())
return HttpResponse("Test")
Or, I replace print(Person.objects.all())
with persons = Person.objects.all()
as shown below:
# "store/views.py"
from django.http import HttpResponse
from .models import Person
def test(request):
persons = Person.objects.all() # Here
# print(Person.objects.all())
return HttpResponse("Test")
Then, when I run test
view, SELECT
query isn't run as shown below:
So, why isn't SELECT
query run in Django?