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
This commit is contained in:
Adrian Holovaty 2005-07-22 18:45:22 +00:00
parent c97efb6799
commit c2a5c49ac2
3 changed files with 21 additions and 22 deletions

View File

@ -107,14 +107,15 @@ provided by the ``order_by`` argument to a lookup::
polls.get_list(
pub_date__year=2005,
pub_date__month=1,
order_by=(("pub_date", "DESC"), ("question", "ASC")),
order_by=('-pub_date', 'question'),
)
The result set above will be ordered by ``pub_date`` (descending), then
by ``question`` (ascending). Just like in models, the ``order_by`` clause
is a list of ordering tuples where the first element is the field and the
second is "ASC" (ascending) or "DESC" (descending). You can also
use the tuple ``(None, "RANDOM")`` to order the result set randomly.
The result set above will be ordered by ``pub_date`` descending, then
by ``question`` ascending. The negative sign in front of "-pub_date" indicates
descending order. Ascending order is implied. To order randomly, use "?", like
so::
polls.get_list(order_by=['?'])
Relationships (joins)
=====================

View File

@ -76,11 +76,11 @@ wide array of options, only ``fields`` is required.
``ordering``
The default ordering for the object, for use by ``get_list`` and the admin::
ordering = (('order_date', 'DESC'),)
ordering = ['-order_date']
This is a tuple of 2-tuples. Each 2-tuple is ``(field_name, ordering_type)``
where ordering_type is either ``"ASC"`` or ``"DESC"``. You can also use the
``(None, "RANDOM")`` for random ordering.
This is a tuple or list of strings. Each string is a field name with an
optional "-" (indicating descending order). Or, you can use the string "?"
to order randomly.
``permissions``
Extra permissions to enter into the permissions table when creating this
@ -662,7 +662,7 @@ object, which has the following options. All are optional.
(This example also has ``search_fields`` defined; see below).
``ordering``
An ordering tuple (see the `Options for models`_, above) that gives a
A list or tuple (see the `Options for models`_, above) that gives a
different ordering for the admin change list. If this isn't given, the
model's default ordering will be used.

View File

@ -14,25 +14,25 @@ application and will focus on creating the public interface -- "views."
A view is a "type" of Web page in your Django application that generally
serves a specific function and has a specific template. For example, in a
weblog application, you might have the following views:
* Blog homepage -- displays the latest few entries.
* Entry "detail" page -- permalink page for a single entry.
* Year-based archive page -- displays all months with entries in the
* Year-based archive page -- displays all months with entries in the
given year.
* Month-based archive page -- displays all days with entries in the
* Month-based archive page -- displays all days with entries in the
given month.
* Day-based archive page -- displays all entries in the given day.
* Comment action -- handles posting comments to a given entry.
In our poll application, we'll have the following four views:
* Poll "archive" page -- displays the latest few polls.
* Poll "detail" page -- displays a poll question, with no results but
with a form to vote.
* Poll "results" page -- displays results for a particular poll.
* Vote action -- handles voting for a particular choice in a particular
poll.
In Django, each view is represented by a simple Python function.
Design your URLs
@ -174,8 +174,7 @@ publication date::
from django.utils.httpwrappers import HttpResponse
def index(request):
latest_poll_list = polls.get_list(order_by=[('pub_date', 'DESC')],
limit=5)
latest_poll_list = polls.get_list(order_by=['-pub_date'], limit=5)
output = ', '.join([p.question for p in latest_poll_list])
return HttpResponse(output)
@ -189,8 +188,7 @@ So let's use Django's template system to separate the design from Python::
from django.utils.httpwrappers import HttpResponse
def index(request):
latest_poll_list = polls.get_list(order_by=[('pub_date', 'DESC')],
limit=5)
latest_poll_list = polls.get_list(order_by=['-pub_date'], limit=5)
t = template_loader.get_template('polls/index')
c = Context(request, {
'latest_poll_list': latest_poll_list,
@ -278,7 +276,7 @@ Two more things to note about 404 views:
* The 404 view is also called if Django doesn't find a match after checking
every regular expression in the URLconf.
* If you don't define your own 404 view -- and simply use the default,
* If you don't define your own 404 view -- and simply use the default,
which is recommended -- you still have one obligation: To create a
``404.html`` template in the root of your template directory. The default
404 view will use that template for all 404 errors.