diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2020-02-18 20:09:48 -0800 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-03-19 12:57:07 +0100 |
| commit | 013147fae2b9168b06c495aa78c10725cab294cd (patch) | |
| tree | 1b176e0c3a78b46396d25ff81a756f10ed7e5032 /django | |
| parent | 142ab6846ac09d6d401e26fc8b6b988a583ac0f5 (diff) | |
Fixed #31285 -- Fixed inherited Meta.ordering of "-pk".
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/sql/compiler.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 92213a4e67..63ca817355 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -709,9 +709,9 @@ class SQLCompiler: field, targets, alias, joins, path, opts, transform_function = 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 unless the attribute name - # of the field is specified. - if field.is_relation and opts.ordering and getattr(field, 'attname', None) != name: + # append the default ordering for that model unless it is the pk + # shortcut or the attribute name of the field that is specified. + if field.is_relation and opts.ordering and getattr(field, 'attname', None) != name and name != 'pk': # Firstly, avoid infinite loops. already_seen = already_seen or set() join_tuple = tuple(getattr(self.query.alias_map[j], 'join_cols', None) for j in joins) |
