From 7a42cfcfdc94c1e7cd653f3140b9eb30492bae4f Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 11 Jul 2019 13:40:36 +0200 Subject: Refs #30557 -- Fixed crash of ordering by ptr fields when Meta.ordering contains F() expressions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Can Sarıgöl for the report. Follow up to 8c5f9906c56ac72fc4f13218dd90bdf9bc8a248b. --- django/db/models/sql/compiler.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 3cab405d2d..52ea717ca6 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -722,6 +722,8 @@ class SQLCompiler: results = [] for item in opts.ordering: + if hasattr(item, 'resolve_expression') and not isinstance(item, OrderBy): + item = item.desc() if descending else item.asc() if isinstance(item, OrderBy): results.append((item, False)) continue -- cgit v1.3