summaryrefslogtreecommitdiff
path: root/django/db/models/sql/compiler.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2014-04-26 03:34:20 -0400
committerSimon Charette <charette.s@gmail.com>2014-04-30 14:23:19 -0400
commit24ec9538b7ca400f68ba08fab380445ca95d7c02 (patch)
tree6aedd8c704ceb9643585ab2b7bc6254d9a12f6bc /django/db/models/sql/compiler.py
parenta5f6cbce07b5f3ab48d931e3fd1883c757fb9b45 (diff)
Fixed #19195 -- Allow explicit ordering by a relation `_id` field.
Thanks to chrisedgemon for the report and shaib, akaariai and timgraham for the review.
Diffstat (limited to 'django/db/models/sql/compiler.py')
-rw-r--r--django/db/models/sql/compiler.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 09b1f7d4d8..6792824ecd 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -464,8 +464,9 @@ class SQLCompiler(object):
field, targets, alias, joins, path, opts = self._setup_joins(pieces, opts, alias)
# If we get to this point and the field is a relation to another model,
- # append the default ordering for that model.
- if field.rel and path and opts.ordering:
+ # append the default ordering for that model unless the attribute name
+ # of the field is specified.
+ if field.rel and path and opts.ordering and name != field.attname:
# Firstly, avoid infinite loops.
if not already_seen:
already_seen = set()