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

@ -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,