From 013147fae2b9168b06c495aa78c10725cab294cd Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Tue, 18 Feb 2020 20:09:48 -0800 Subject: Fixed #31285 -- Fixed inherited Meta.ordering of "-pk". --- django/db/models/sql/compiler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'django/db/models/sql') 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) -- cgit v1.3