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

View File

@ -76,11 +76,11 @@ wide array of options, only ``fields`` is required.
``ordering`` ``ordering``
The default ordering for the object, for use by ``get_list`` and the admin:: 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)`` This is a tuple or list of strings. Each string is a field name with an
where ordering_type is either ``"ASC"`` or ``"DESC"``. You can also use the optional "-" (indicating descending order). Or, you can use the string "?"
``(None, "RANDOM")`` for random ordering. to order randomly.
``permissions`` ``permissions``
Extra permissions to enter into the permissions table when creating this 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). (This example also has ``search_fields`` defined; see below).
``ordering`` ``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 different ordering for the admin change list. If this isn't given, the
model's default ordering will be used. model's default ordering will be used.

View File

@ -174,8 +174,7 @@ publication date::
from django.utils.httpwrappers import HttpResponse from django.utils.httpwrappers import HttpResponse
def index(request): def index(request):
latest_poll_list = polls.get_list(order_by=[('pub_date', 'DESC')], latest_poll_list = polls.get_list(order_by=['-pub_date'], limit=5)
limit=5)
output = ', '.join([p.question for p in latest_poll_list]) output = ', '.join([p.question for p in latest_poll_list])
return HttpResponse(output) 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 from django.utils.httpwrappers import HttpResponse
def index(request): def index(request):
latest_poll_list = polls.get_list(order_by=[('pub_date', 'DESC')], latest_poll_list = polls.get_list(order_by=['-pub_date'], limit=5)
limit=5)
t = template_loader.get_template('polls/index') t = template_loader.get_template('polls/index')
c = Context(request, { c = Context(request, {
'latest_poll_list': latest_poll_list, 'latest_poll_list': latest_poll_list,