summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-18 10:21:50 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-18 10:21:50 +0000
commit670be13986b74f252d479ee2b7f74da8655273f6 (patch)
tree61a2a676086e0b5a2261961879cc1d09e9678949 /django/db/models/sql
parent8b52e8e40e100f02f09138947fee706c00c3ccbc (diff)
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
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/datastructures.py7
-rw-r--r--django/db/models/sql/query.py15
2 files changed, 12 insertions, 10 deletions
diff --git a/django/db/models/sql/datastructures.py b/django/db/models/sql/datastructures.py
index bc21fb3b68..cb54a564f8 100644
--- a/django/db/models/sql/datastructures.py
+++ b/django/db/models/sql/datastructures.py
@@ -9,7 +9,12 @@ class EmptyResultSet(Exception):
class FullResultSet(Exception):
pass
-class JoinError(Exception):
+class MultiJoin(Exception):
+ """
+ Used by join construction code to indicate the point at which a
+ multi-valued join was attempted (if the caller wants to treat that
+ exceptionally).
+ """
def __init__(self, level):
self.level = level
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 771ee55e12..c153fe1e55 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -18,7 +18,7 @@ from django.db.models.sql.where import WhereNode, EverythingNode, AND, OR
from django.db.models.sql.datastructures import Count
from django.db.models.fields import FieldDoesNotExist
from django.core.exceptions import FieldError
-from datastructures import EmptyResultSet, Empty, JoinError
+from datastructures import EmptyResultSet, Empty, MultiJoin
from constants import *
try:
@@ -523,11 +523,8 @@ class Query(object):
pieces = name.split(LOOKUP_SEP)
if not alias:
alias = self.get_initial_alias()
- try:
- field, target, opts, joins, last = self.setup_joins(pieces, opts,
- alias, False, False)
- except JoinError:
- raise FieldError("Cannot order by many-valued field: '%s'" % name)
+ field, target, opts, joins, last = self.setup_joins(pieces, opts,
+ alias, False)
alias = joins[-1]
col = target.column
@@ -848,7 +845,7 @@ class Query(object):
try:
field, target, opts, join_list, last = self.setup_joins(parts, opts,
alias, (connector == AND), allow_many)
- except JoinError, e:
+ except MultiJoin, e:
self.split_exclude(filter_expr, LOOKUP_SEP.join(parts[:e.level]))
return
final = len(join_list)
@@ -1007,7 +1004,7 @@ class Query(object):
if not allow_many and (m2m or not direct):
for alias in joins:
self.unref_alias(alias)
- raise JoinError(pos + 1)
+ raise MultiJoin(pos + 1)
if model:
# The field lives on a base class of the current model.
alias_list = []
@@ -1175,7 +1172,7 @@ class Query(object):
name.split(LOOKUP_SEP), opts, alias, False, allow_m2m,
True)
self.select.append((joins[-1], target.column))
- except JoinError:
+ except MultiJoin:
raise FieldError("Invalid field name: '%s'" % name)
def add_ordering(self, *ordering):