summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/compiler.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index f1bb10e228..a695025167 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -253,10 +253,17 @@ class SQLCompiler(object):
descending = True if order == 'DESC' else False
if col in self.query.annotation_select:
+ # Reference to expression in SELECT clause
order_by.append((
OrderBy(Ref(col, self.query.annotation_select[col]), descending=descending),
True))
continue
+ if col in self.query.annotations:
+ # References to an expression which is masked out of the SELECT clause
+ order_by.append((
+ OrderBy(self.query.annotations[col], descending=descending),
+ False))
+ continue
if '.' in field:
# This came in through an extra(order_by=...) addition. Pass it