diff --git a/djangotoolbox/db/basecompiler.py b/djangotoolbox/db/basecompiler.py index 71d9ec8..a93248f 100644 --- a/djangotoolbox/db/basecompiler.py +++ b/djangotoolbox/db/basecompiler.py @@ -11,6 +11,7 @@ from django.db.utils import DatabaseError, IntegrityError from django.utils.tree import Node from django.db import connections +from ..fields import RawFakeField try: from django.db.models.sql.where import SubqueryConstraint @@ -553,7 +554,10 @@ def _get_ordering(self): if name == 'pk': name = opts.pk.name - field_ordering.append((opts.get_field(name), ascending)) + if '.' in name: + field_ordering.append((RawFakeField(name), ascending)) + else: + field_ordering.append((opts.get_field(name), ascending)) return field_ordering diff --git a/djangotoolbox/fields.py b/djangotoolbox/fields.py index c4e877b..4a341a1 100644 --- a/djangotoolbox/fields.py +++ b/djangotoolbox/fields.py @@ -26,6 +26,17 @@ def __init__(self, field, value): setattr(self, field.attname, value) +class RawFakeField(object): + primary_key = False + + def __init__(self, name): + self.name = name + self.column = name + + def get_internal_type(self): + return 'RawField' + + class RawField(models.Field): """ Generic field to store anything your database backend allows you