6.6. ORM All
6.6.1. All
>>> Customer.objects.all()
<QuerySet [<Customer: Melissa Lewis>, <Customer: Mark Watney>, <Customer: Rick Martinez>, <Customer: Alex Vogel>, <Customer: Beth Johansson>, <Customer: Chris Beck>, <Customer: Alice ...>, <Customer: Alice ...>, <Customer: Bob ...>, <Customer: Mark Watney>, <Customer: Melissa Lewis>, <Customer: Rick Martinez>, <Customer: Alex Vogel>, <Customer: Beth Johanssen>, <Customer: Chris Beck>]>
>>> Customer.objects.update(is_verified=True)
15
>>> Customer.objects.all().update(is_verified=True)
15
6.6.2. For Loop
>>> for customer in Customer.objects.all():
... print(customer)
...
Mark Watney
Rick Martinez
Alex Vogel
Beth Johansson
Chris Beck
Melissa Lewis
6.6.3. Order By
QuerySet.order_by()
>>> Customer.objects.all().order_by('lastname')
<QuerySet [<Customer: Chris Beck>, <Customer: Beth Johansson>, <Customer: Melissa Lewis>, <Customer: Rick Martinez>, <Customer: Alex Vogel>, <Customer: Mark Watney>]>
>>> Customer.objects.all().order_by('-lastname')
<QuerySet [<Customer: Mark Watney>, <Customer: Alex Vogel>, <Customer: Rick Martinez>, <Customer: Melissa Lewis>, <Customer: Beth Johansson>, <Customer: Chris Beck>]>
>>> Customer.objects.all().order_by('-lastname', 'firstname')
<QuerySet [<Customer: Mark Watney>, <Customer: Alex Vogel>, <Customer: Rick Martinez>, <Customer: Melissa Lewis>, <Customer: Beth Johansson>, <Customer: Chris Beck>]>
6.6.4. Values
QuerySet.values()
>>> Customer.objects.all().values('lastname')
<QuerySet [{'lastname': 'Watney'}, {'lastname': 'Martinez'}, {'lastname': 'Vogel'}, {'lastname': 'Johansson'}, {'lastname': 'Beck'}, {'lastname': 'Lewis'}]>
>>> Customer.objects.all().values('lastname', 'firstname')
<QuerySet [{'lastname': 'Watney', 'firstname': 'Mark'}, {'lastname': 'Martinez', 'firstname': 'Rick'}, {'lastname': 'Vogel', 'firstname': 'Alex'}, {'lastname': 'Johansson', 'firstname': 'Beth'}, {'lastname': 'Beck', 'firstname': 'Chris'}, {'lastname': 'Lewis', 'firstname': 'Melissa'}]>
6.6.5. Values List
QuerySet.values_list()
flat=True
>>> Customer.objects.all().values_list('lastname')
<QuerySet [('Watney',), ('Martinez',), ('Vogel',), ('Johansson',), ('Beck',), ('Lewis',)]>
>>> Customer.objects.all().values_list('lastname', 'firstname')
<QuerySet [('Watney', 'Mark'), ('Martinez', 'Rick'), ('Vogel', 'Alex'), ('Johansson', 'Beth'), ('Beck', 'Chris'), ('Lewis', 'Melissa')]>
>>> Customer.objects.all().values_list('lastname', flat=True)
<QuerySet ['Watney', 'Martinez', 'Vogel', 'Johansson', 'Beck', 'Lewis']>
6.6.6. As List
list()
>>> list(Customer.objects.all().values_list('lastname', flat=True))
['Watney', 'Martinez', 'Vogel', 'Johansson', 'Beck', 'Lewis']
6.6.7. As Dict
dict()
>>> dict(Customer.objects.all().values_list('lastname', 'firstname'))
{'Watney': 'Mark', 'Martinez': 'Rick', 'Vogel': 'Alex', 'Johansson': 'Beth', 'Beck': 'Chris', 'Lewis': 'Melissa'}
6.6.8. SQL Query
>>> data = Customer.objects.all()
>>>
>>> data
<QuerySet [<Customer: Melissa Lewis>, <Customer: Mark Watney>, <Customer: Rick Martinez>, <Customer: Alex Vogel>, <Customer: Beth Johansson>, <Customer: Chris Beck>, <Customer: Alice ...>, <Customer: Alice ...>, <Customer: Bob ...>, <Customer: Mark Watney>, <Customer: Melissa Lewis>, <Customer: Rick Martinez>, <Customer: Alex Vogel>, <Customer: Beth Johanssen>, <Customer: Chris Beck>]>
>>>
>>> print(data.query)
SELECT "shop_customer"."id", "shop_customer"."uuid", "shop_customer"."created_user_id", "shop_customer"."created_date", "shop_customer"."modified_user_id", "shop_customer"."modified_date", "shop_customer"."is_deleted", "shop_customer"."comment", "shop_customer"."firstname", "shop_customer"."lastname", "shop_customer"."birthdate", "shop_customer"."gender", "shop_customer"."tax_number", "shop_customer"."email", "shop_customer"."phone", "shop_customer"."image", "shop_customer"."is_verified" FROM "shop_customer"
Using .values_list()
will limit number of columns in the query:
>>> data = Customer.objects.all().values_list('lastname', 'firstname')
>>>
>>> data
<QuerySet [('Watney', 'Mark'), ('Martinez', 'Rick'), ('Vogel', 'Alex'), ('Johansson', 'Beth'), ('Beck', 'Chris'), ('Lewis', 'Melissa')]>
>>>
>>> print(data.query)
SELECT "shop_customer"."lastname", "shop_customer"."firstname" FROM "shop_customer"
Using .filter()
will limit number of rows in the query:
>>> data = Customer.objects.filter(gender='female').values_list('lastname', 'firstname')
>>>
>>> data
<QuerySet []>
>>>
>>> print(data.query)
SELECT "shop_customer"."lastname", "shop_customer"."firstname" FROM "shop_customer" WHERE "shop_customer"."gender" = female
6.6.9. Assignments
# doctest: +SKIP_FILE
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: Database ORM All
# - Difficulty: easy
# - Lines: 1
# - Minutes: 3
# %% English
# 0. Use `myproject.shop`
# 1. Define variable `result` with result of query:
# Select all customers
# %% Polish
# 0. Użyj `myproject.shop`
# 1. Zdefiniuj zmienną `result` z wynikiem zapytania:
# Wybierz wszystkich klientów
# %% Hints
# - `.all()`
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'
>>> from django.db.models.query import QuerySet
>>> assert type(result) is QuerySet, \
'Variable `result` has invalid type, should be QuerySet'
>>> from pprint import pprint
>>> pprint(result)
<QuerySet [<Customer: Mark Watney>, <Customer: Melissa Lewis>, <Customer: Rick Martinez>, <Customer: Alex Vogel>, <Customer: Beth Johanssen>, <Customer: Chris Beck>]>
"""
# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()
from shop.models import Customer
# Define variable `result` with result of query:
# Select all Customers
# type: QuerySet
result = ...
# doctest: +SKIP_FILE
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: Database ORM All
# - Difficulty: easy
# - Lines: 3
# - Minutes: 3
# %% English
# 0. Use `myproject.shop`
# 1. Define variable `result: list`
# 2. Iterate over all customers and add lastname to `result`
# %% Polish
# 0. Użyj `myproject.shop`
# 1. Zdefiniuj zmienną `result: list`
# 2. Iteruj po wszystkich klientach i dodaj lastname do `result`
# %% Hints
# - `.all()`
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'
>>> assert type(result) is list, \
'Variable `result` has invalid type, should be list'
>>> from pprint import pprint
>>> pprint(result)
['Watney', 'Lewis', 'Martinez', 'Vogel', 'Johanssen', 'Beck']
"""
# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()
from shop.models import Customer
# Define variable `result: list`
# Iterate over all customers and add lastname to `result`
# type: list[str]
result = ...
# doctest: +SKIP_FILE
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: Database ORM All
# - Difficulty: easy
# - Lines: 1
# - Minutes: 3
# %% English
# 0. Use `myproject.shop`
# 1. Define variable `result` with result of query:
# Select all customers
# Order by `lastname`
# %% Polish
# 0. Użyj `myproject.shop`
# 1. Zdefiniuj zmienną `result` z wynikiem zapytania:
# Wybierz wszystkich klientów
# Posortuj po `lastname`
# %% Hints
# - `.order_by()`
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'
>>> from django.db.models.query import QuerySet
>>> assert type(result) is QuerySet, \
'Variable `result` has invalid type, should be QuerySet'
>>> from pprint import pprint
>>> pprint(result)
<QuerySet [<Customer: Chris Beck>, <Customer: Beth Johanssen>, <Customer: Melissa Lewis>, <Customer: Rick Martinez>, <Customer: Alex Vogel>, <Customer: Mark Watney>]>
"""
# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()
from shop.models import Customer
# Define variable `result` with result of query:
# Select all Customers
# Order by `lastname`
# type: QuerySet
result = ...
# doctest: +SKIP_FILE
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: Database ORM All
# - Difficulty: easy
# - Lines: 1
# - Minutes: 3
# %% English
# 0. Use `myproject.shop`
# 1. Define variable `result` with result of query:
# Select all customers
# Order by `lastname` (descending) and `firstname` (ascending)
# %% Polish
# 0. Użyj `myproject.shop`
# 1. Zdefiniuj zmienną `result` z wynikiem zapytania:
# Wybierz wszystkich klientów
# Posortuj po `lastname` (malejąco) i `firstname` (rosnąco)
# %% Hints
# - `.order_by()`
# - `-column` for descending order
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'
>>> from django.db.models.query import QuerySet
>>> assert type(result) is QuerySet, \
'Variable `result` has invalid type, should be QuerySet'
>>> from pprint import pprint
>>> pprint(result)
<QuerySet [<Customer: Mark Watney>, <Customer: Alex Vogel>, <Customer: Rick Martinez>, <Customer: Melissa Lewis>, <Customer: Beth Johanssen>, <Customer: Chris Beck>]>
"""
# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()
from shop.models import Customer
# Define variable `result` with result of query:
# Select all Customers
# Order by `lastname` (descending) and `firstname` (ascending)
# type: QuerySet
result = ...
# doctest: +SKIP_FILE
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: Database ORM All
# - Difficulty: easy
# - Lines: 1
# - Minutes: 3
# %% English
# 0. Use `myproject.shop`
# 1. Define variable `result` with result of query:
# Select `firstname` and `lastname` from all customers
# 2. Result should be a `QuerySet` of` list[dict]`
# %% Polish
# 0. Użyj `myproject.shop`
# 1. Zdefiniuj zmienną `result` z wynikiem zapytania:
# Wybierz `firstname` i `lastname` wszystkich klientów
# 2. Wynik powinien być jako `QuerySet` od `list[dict]`
# %% Hints
# - `.values()`
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'
>>> from django.db.models.query import QuerySet
>>> assert type(result) is QuerySet, \
'Variable `result` has invalid type, should be QuerySet'
>>> from pprint import pprint
>>> pprint(result)
<QuerySet [{'firstname': 'Mark', 'lastname': 'Watney'}, {'firstname': 'Melissa', 'lastname': 'Lewis'}, {'firstname': 'Rick', 'lastname': 'Martinez'}, {'firstname': 'Alex', 'lastname': 'Vogel'}, {'firstname': 'Beth', 'lastname': 'Johanssen'}, {'firstname': 'Chris', 'lastname': 'Beck'}]>
"""
# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()
from shop.models import Customer
# Define variable `result` with result of query:
# Select `firstname` and `lastname` from all Customers
# Result should be a QuerySet of list[dict]
# type: QuerySet
result = ...
# doctest: +SKIP_FILE
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: Database ORM All
# - Difficulty: easy
# - Lines: 1
# - Minutes: 3
# %% English
# 0. Use `myproject.shop`
# 1. Define variable `result` with result of query:
# Select `firstname` and `lastname` of all customers
# 2. Result should be a `QuerySet` of `list[tuple]`
# %% Polish
# 0. Użyj `myproject.shop`
# 1. Zdefiniuj zmienną `result` z wynikiem zapytania:
# Wybierz `firstname` i `lastname` wszystkich klientów
# 2. Wynik powinien być jako `QuerySet` od `list[tuple]`
# %% Hints
# - `.values_list()`
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'
>>> from django.db.models.query import QuerySet
>>> assert type(result) is QuerySet, \
'Variable `result` has invalid type, should be QuerySet'
>>> from pprint import pprint
>>> pprint(result)
<QuerySet [('Mark', 'Watney'), ('Melissa', 'Lewis'), ('Rick', 'Martinez'), ('Alex', 'Vogel'), ('Beth', 'Johanssen'), ('Chris', 'Beck')]>
"""
# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()
from shop.models import Customer
# Define variable `result` with result of query:
# Select `firstname` and `lastname` of all Customers
# Result should be a QuerySet of list[tuple]
# type: QuerySet
result = ...
# doctest: +SKIP_FILE
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: Database ORM All
# - Difficulty: easy
# - Lines: 1
# - Minutes: 3
# %% English
# 0. Use `myproject.shop`
# 1. Define variable `result` with result of query:
# Select `lastname` of all customers
# 2. Result should be a `QuerySet` of `list[str]`
# %% Polish
# 0. Użyj `myproject.shop`
# 1. Zdefiniuj zmienną `result` z wynikiem zapytania:
# Wybierz `lastname` wszystkich klientów
# 2. Wynik powinien być jako `QuerySet` od `list[str]`
# %% Hints
# - `.values_list(flat=True)`
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'
>>> from django.db.models.query import QuerySet
>>> assert type(result) is QuerySet, \
'Variable `result` has invalid type, should be QuerySet'
>>> from pprint import pprint
>>> pprint(result)
<QuerySet ['Watney', 'Lewis', 'Martinez', 'Vogel', 'Johanssen', 'Beck']>
"""
# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()
from shop.models import Customer
# Define variable `result` with result of query:
# Select `lastname` of all Customers
# Result should be a QuerySet of list[str]
# type: QuerySet
result = ...
# doctest: +SKIP_FILE
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: Database ORM All
# - Difficulty: easy
# - Lines: 1
# - Minutes: 3
# %% English
# 0. Use `myproject.shop`
# 1. Define variable `result` with result of query:
# Select `lastname` of all customers
# 2. Result should be a `dict[str,str]`
# %% Polish
# 0. Użyj `myproject.shop`
# 1. Zdefiniuj zmienną `result` z wynikiem zapytania:
# Wybierz `lastname` wszystkich klientów
# 2. Wynik powinien być jako `dict[str,str]`
# %% Hints
# - `dict()`
# - `.values_list()`
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'
>>> assert type(result) is dict, \
'Variable `result` has invalid type, should be dict'
>>> from pprint import pprint
>>> pprint(result)
{'Alex': 'Vogel',
'Beth': 'Johanssen',
'Chris': 'Beck',
'Mark': 'Watney',
'Melissa': 'Lewis',
'Rick': 'Martinez'}
"""
# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()
from shop.models import Customer
# Define variable `result` with result of query:
# Select `lastname` of all Customers
# Result should be a dict[str,str]
# type: dict[str,str]
result = ...
# doctest: +SKIP_FILE
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: Database ORM All
# - Difficulty: easy
# - Lines: 1
# - Minutes: 3
# %% English
# 0. Use `myproject.shop`
# 1. Define variable `result` with SQL query of:
# Select all customers
# %% Polish
# 0. Użyj `myproject.shop`
# 1. Zdefiniuj zmienną `result` z zapytaniem SQL dla:
# Wybierz wszystkich klientów
# %% Hints
# - `.all()`
# - `.qurery`
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'
>>> assert type(result) is str, \
'Variable `result` has invalid type, should be str'
>>> from pprint import pprint
>>> pprint(result)
('SELECT "shop_customer"."id", "shop_customer"."uuid", '
'"shop_customer"."created_user_id", "shop_customer"."created_date", '
'"shop_customer"."modified_user_id", "shop_customer"."modified_date", '
'"shop_customer"."is_deleted", "shop_customer"."comment", '
'"shop_customer"."firstname", "shop_customer"."lastname", '
'"shop_customer"."birthdate", "shop_customer"."gender", '
'"shop_customer"."tax_number", "shop_customer"."email", '
'"shop_customer"."phone", "shop_customer"."image", '
'"shop_customer"."is_verified" FROM "shop_customer"')
"""
# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()
from shop.models import Customer
# Define variable `result` with SQL query of:
# Select all Customers
# type: str
result = ...