From 36c7e957889f94796535a733baee26ac86536910 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 11 Oct 2013 20:12:23 +0200 Subject: [PATCH] support nulls_last in sqlite --- ox/django/query.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ox/django/query.py b/ox/django/query.py index 22f6b96..f96a96d 100644 --- a/ox/django/query.py +++ b/ox/django/query.py @@ -25,7 +25,20 @@ class SQLCompiler(SQLCompiler): def get_ordering(self): result, group_by = super(SQLCompiler, self).get_ordering() if self.query.nulls_last and len(result): - result = map(lambda e: e + ' NULLS LAST', result) + if self.connection.vendor == 'sqlite': + _result = [] + for r in result: + if r.endswith(' DESC'): + _r = r[:-len(' DESC')] + elif r.endswith(' ASC'): + _r = r[:-len(' ASC')] + _result.append(_r + ' IS NULL') + _result.append(r) + + result = _result + else: + result = map(lambda e: e + ' NULLS LAST', result) + print result return result, group_by class Query(Query):