Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #153 -- Changed docs to use new ordering syntax

git-svn-id: http://code.djangoproject.com/svn/django/trunk@299 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c2a5c49ac279f1e0e2cdbec3de0d957893b9c839 1 parent c97efb6
Adrian Holovaty authored
13  docs/db-api.txt
@@ -107,14 +107,15 @@ provided by the ``order_by`` argument to a lookup::
107 107
     polls.get_list(
108 108
         pub_date__year=2005,
109 109
         pub_date__month=1,
110  
-        order_by=(("pub_date", "DESC"), ("question", "ASC")),
  110
+        order_by=('-pub_date', 'question'),
111 111
     )
112 112
 
113  
-The result set above will be ordered by ``pub_date`` (descending), then
114  
-by ``question`` (ascending).  Just like in models, the ``order_by`` clause
115  
-is a list of ordering tuples where the first element is the field and the
116  
-second is "ASC" (ascending) or "DESC" (descending).  You can also
117  
-use the tuple ``(None, "RANDOM")`` to order the result set randomly.
  113
+The result set above will be ordered by ``pub_date`` descending, then
  114
+by ``question`` ascending. The negative sign in front of "-pub_date" indicates
  115
+descending order. Ascending order is implied. To order randomly, use "?", like
  116
+so::
  117
+
  118
+    polls.get_list(order_by=['?'])
118 119
 
119 120
 Relationships (joins)
120 121
 =====================
10  docs/model-api.txt
@@ -76,11 +76,11 @@ wide array of options, only ``fields`` is required.
76 76
 ``ordering``
77 77
     The default ordering for the object, for use by ``get_list`` and the admin::
78 78
 
79  
-        ordering = (('order_date', 'DESC'),)
  79
+        ordering = ['-order_date']
80 80
 
81  
-    This is a tuple of 2-tuples. Each 2-tuple is ``(field_name, ordering_type)``
82  
-    where ordering_type is either ``"ASC"`` or ``"DESC"``.  You can also use the
83  
-    ``(None, "RANDOM")`` for random ordering.
  81
+    This is a tuple or list of strings. Each string is a field name with an
  82
+    optional "-" (indicating descending order). Or, you can use the string "?"
  83
+    to order randomly.
84 84
 
85 85
 ``permissions``
86 86
     Extra permissions to enter into the permissions table when creating this
@@ -662,7 +662,7 @@ object, which has the following options. All are optional.
662 662
     (This example also has ``search_fields`` defined; see below).
663 663
 
664 664
 ``ordering``
665  
-    An ordering tuple (see the `Options for models`_, above) that gives a
  665
+    A list or tuple (see the `Options for models`_, above) that gives a
666 666
     different ordering for the admin change list. If this isn't given, the
667 667
     model's default ordering will be used.
668 668
 
20  docs/tutorial03.txt
@@ -14,25 +14,25 @@ application and will focus on creating the public interface -- "views."
14 14
     A view is a "type" of Web page in your Django application that generally
15 15
     serves a specific function and has a specific template. For example, in a
16 16
     weblog application, you might have the following views:
17  
-    
  17
+
18 18
         * Blog homepage -- displays the latest few entries.
19 19
         * Entry "detail" page -- permalink page for a single entry.
20  
-        * Year-based archive page -- displays all months with entries in the 
  20
+        * Year-based archive page -- displays all months with entries in the
21 21
           given year.
22  
-        * Month-based archive page -- displays all days with entries in the 
  22
+        * Month-based archive page -- displays all days with entries in the
23 23
           given month.
24 24
         * Day-based archive page -- displays all entries in the given day.
25 25
         * Comment action -- handles posting comments to a given entry.
26  
-    
  26
+
27 27
     In our poll application, we'll have the following four views:
28  
-    
  28
+
29 29
         * Poll "archive" page -- displays the latest few polls.
30 30
         * Poll "detail" page -- displays a poll question, with no results but
31 31
           with a form to vote.
32 32
         * Poll "results" page -- displays results for a particular poll.
33 33
         * Vote action -- handles voting for a particular choice in a particular
34 34
           poll.
35  
-    
  35
+
36 36
     In Django, each view is represented by a simple Python function.
37 37
 
38 38
 Design your URLs
@@ -174,8 +174,7 @@ publication date::
174 174
     from django.utils.httpwrappers import HttpResponse
175 175
 
176 176
     def index(request):
177  
-        latest_poll_list = polls.get_list(order_by=[('pub_date', 'DESC')],
178  
-            limit=5)
  177
+        latest_poll_list = polls.get_list(order_by=['-pub_date'], limit=5)
179 178
         output = ', '.join([p.question for p in latest_poll_list])
180 179
         return HttpResponse(output)
181 180
 
@@ -189,8 +188,7 @@ So let's use Django's template system to separate the design from Python::
189 188
     from django.utils.httpwrappers import HttpResponse
190 189
 
191 190
     def index(request):
192  
-        latest_poll_list = polls.get_list(order_by=[('pub_date', 'DESC')],
193  
-            limit=5)
  191
+        latest_poll_list = polls.get_list(order_by=['-pub_date'], limit=5)
194 192
         t = template_loader.get_template('polls/index')
195 193
         c = Context(request, {
196 194
             'latest_poll_list': latest_poll_list,
@@ -278,7 +276,7 @@ Two more things to note about 404 views:
278 276
 
279 277
     * The 404 view is also called if Django doesn't find a match after checking
280 278
       every regular expression in the URLconf.
281  
-    * If you don't define your own 404 view -- and simply use the default, 
  279
+    * If you don't define your own 404 view -- and simply use the default,
282 280
       which is recommended -- you still have one obligation: To create a
283 281
       ``404.html`` template in the root of your template directory. The default
284 282
       404 view will use that template for all 404 errors.

0 notes on commit c2a5c49

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