From ee596888e1149864e7828f5cf63c0eda395744c3 Mon Sep 17 00:00:00 2001 From: Anssi Kääriäinen Date: Wed, 20 Jan 2016 11:05:48 +0200 Subject: Fixed #26092 -- Fixed QuerySet.order_by() regression with an M2M through model. --- django/db/models/sql/compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 47a85bb9a4..3b804dc0b0 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -555,7 +555,7 @@ class SQLCompiler(object): # 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 path and opts.ordering and name != field.attname: + if field.is_relation and opts.ordering and getattr(field, 'attname', None) != name: # Firstly, avoid infinite loops. if not already_seen: already_seen = set() -- cgit v1.3