diff options
| author | Simon Charette <charette.s@gmail.com> | 2014-04-26 03:34:20 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2014-04-30 14:26:39 -0400 |
| commit | a6ecd5dbb34249f756a337c359eef1e8d78dc01e (patch) | |
| tree | be80a1387b8541e07db3da89e0d774597dffbfe5 /django/db/models/sql | |
| parent | 1084456ac2e707fc562906e95ad78f409dcc9325 (diff) | |
[1.7.x] Fixed #19195 -- Allow explicit ordering by a relation `_id` field.
Thanks to chrisedgemon for the report and shaib, akaariai and
timgraham for the review.
Backport of 24ec9538b7 from master
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/compiler.py | 5 |
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() |
