diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-20 12:24:33 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-20 12:25:02 +0200 |
| commit | d1eb9b29945707c78f524b57577ef87b498cdaa0 (patch) | |
| tree | 4eacf1f5412582450a38d8eff2f6f0a405b11f78 /docs/topics | |
| parent | 9967faab0b664306c377fee931317e0dccb134ea (diff) | |
[4.2.x] Improved examples in docs about raw SQL queries.
Regression in 14459f80ee3a9e005989db37c26fd13bb6d2fab2.
Backport of 498195bda492d09ed00d05ab268cad4b8e5c9f21 from main
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/db/sql.txt | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/docs/topics/db/sql.txt b/docs/topics/db/sql.txt index 47a7ea39e1..42143fd118 100644 --- a/docs/topics/db/sql.txt +++ b/docs/topics/db/sql.txt @@ -121,11 +121,13 @@ had ``Person`` data in it, you could easily map it into ``Person`` instances: .. code-block:: pycon >>> Person.objects.raw( - ... """SELECT first AS first_name, - ... last AS last_name, - ... bd AS birth_date, - ... pk AS id, - ... FROM some_other_table""" + ... """ + ... SELECT first AS first_name, + ... last AS last_name, + ... bd AS birth_date, + ... pk AS id, + ... FROM some_other_table + ... """ ... ) As long as the names match, the model instances will be created correctly. @@ -175,8 +177,9 @@ fields that are omitted from the query will be loaded on demand. For example: >>> for p in Person.objects.raw("SELECT id, first_name FROM myapp_person"): ... print( - ... p.first_name, p.last_name # This will be retrieved by the original query - ... ) # This will be retrieved on demand + ... p.first_name, # This will be retrieved by the original query + ... p.last_name, # This will be retrieved on demand + ... ) ... John Smith Jane Jones |
