Changeset 299
- Timestamp:
- 07/22/05 13:45:22 (3 years ago)
- Files:
-
- django/trunk/docs/db-api.txt (modified) (1 diff)
- django/trunk/docs/model-api.txt (modified) (2 diffs)
- django/trunk/docs/tutorial03.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/db-api.txt
r212 r299 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) django/trunk/docs/model-api.txt
r283 r299 77 77 The default ordering for the object, for use by ``get_list`` and the admin:: 78 78 79 ordering = (('order_date', 'DESC'),)80 81 This is a tuple o f 2-tuples. Each 2-tuple is ``(field_name, ordering_type)``82 where ordering_type is either ``"ASC"`` or ``"DESC"``. You can also use the83 ``(None, "RANDOM")`` for random ordering.79 ordering = ['-order_date'] 80 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`` … … 663 663 664 664 ``ordering`` 665 A n orderingtuple (see the `Options for models`_, above) that gives a665 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. django/trunk/docs/tutorial03.txt
r280 r299 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 … … 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 … … 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) … … 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, { … … 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
