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):