From 670be13986b74f252d479ee2b7f74da8655273f6 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Tue, 18 Mar 2008 10:21:50 +0000 Subject: queryset-refactor: Undo [7220] and allow ordering on multi-valued field. Some people will shoot themselves in the foot with this. That's bad luck. The reason we need it is because some data semantics cannot be expressed in Django's ORM and that shouldn't prevent ordering on that data. For example, filtering suburbs by a geographic region and then ordering on the suburb names. The names might not be unique outside that region, but unique inside it. Django cannot know that (you can't tell the model about it), so we trust the caller. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7285 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/db-api.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/db-api.txt b/docs/db-api.txt index af5ba8ce49..e15b0b2176 100644 --- a/docs/db-api.txt +++ b/docs/db-api.txt @@ -510,12 +510,13 @@ primary key if there is no ``Meta.ordering`` specified. For example:: ...since the ``Blog`` model has no default ordering specified. -You can only order by model fields that have a single value attached to them -for each instance of the model. For example, non-relations, ``ForeignKey`` and -``OneToOneField`` fields. Explicitly, you can't order by a ``ManyToManyField`` -or a reverse ``ForeignKey`` relation. There's no naturally correct ordering -for many-valued fields and a lot of the alternatives are not psosible to -express in SQL very efficiently. +It is permissible to specify a multi-valued field to order the results by (for +example, a ``ManyToMany`` field). Normally this won't be a sensible thing to +do and it's really an advanced usage feature. However, if you know that your +queryset's filtering or available data implies that there will only be one +ordering piece of data for each of the main items you are selecting, the +ordering may well be exactly what you want to do. Use ordering on multi-valued +fields with care and make sure the results are what you expect. **New in Django development version:** If you don't want any ordering to be applied to a query, not even the default ordering, call ``order_by()`` with no -- cgit v1.3