Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12519 -- Corrected documentation on .raw() queries. Thanks to …

…boralyl for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12561 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6f9ba54bf5f52e8a5dde06763de60331537e4386 1 parent d792737
Russell Keith-Magee authored February 24, 2010

Showing 1 changed file with 10 additions and 6 deletions. Show diff stats Hide diff stats

  1. 16  docs/topics/db/sql.txt
16  docs/topics/db/sql.txt
@@ -25,8 +25,10 @@ return model instances:
25 25
 
26 26
 .. method:: Manager.raw(raw_query, params=None, translations=None)
27 27
 
28  
-This method method takes a raw SQL query, executes it, and returns model
29  
-instances.
  28
+This method method takes a raw SQL query, executes it, and returns a
  29
+:class:`~django.db.models.query.RawQuerySet` instance. This
  30
+:class:`~django.db.models.query.RawQuerySet` instance can be iterated
  31
+over just like an normal QuerySet to provide object instances.
30 32
 
31 33
 This is best illustrated with an example. Suppose you've got the following model::
32 34
 
@@ -37,8 +39,10 @@ This is best illustrated with an example. Suppose you've got the following model
37 39
 
38 40
 You could then execute custom SQL like so::
39 41
 
40  
-    >>> Person.objects.raw('SELECT * from myapp_person')
41  
-    [<Person: John Doe>, <Person: Jane Doe>, ...]
  42
+    >>> for p in Person.objects.raw('SELECT * FROM myapp_person'):
  43
+    ...     print p
  44
+    John Smith
  45
+    Jane Jones
42 46
 
43 47
 .. admonition:: Model table names
44 48
 
@@ -110,7 +114,7 @@ Deferring model fields
110 114
 
111 115
 Fields may also be left out::
112 116
 
113  
-    >>> people = Person.objects.raw('SELECT id, first_name FROM myapp_person'):
  117
+    >>> people = Person.objects.raw('SELECT id, first_name FROM myapp_person')
114 118
 
115 119
 The ``Person`` objects returned by this query will be :ref:`deferred
116 120
 <queryset-defer>` model instances. This means that the fields that are omitted
@@ -142,7 +146,7 @@ of people with their ages calculated by the database::
142 146
 
143 147
     >>> people = Person.objects.raw('SELECT *, age(birth_date) AS age FROM myapp_person')
144 148
     >>> for p in people:
145  
-    ...   print "%s is %s." % (p.first_name, p.age)
  149
+    ...     print "%s is %s." % (p.first_name, p.age)
146 150
     John is 37.
147 151
     Jane is 42.
148 152
     ...

0 notes on commit 6f9ba54

Please sign in to comment.
Something went wrong with that request. Please try again.