fix ordering on int fields
[matthijs/upstream/django-ldapdb.git] / ldapdb / models / query.py
index fc211b45715099f3e48c2ca3eb489635249c921b..bbb46e2553f991e124bbcbc16d1ee3bed0d71beb 100644 (file)
@@ -96,15 +96,20 @@ class Compiler(object):
         else:
             ordering = query.order_by or query.model._meta.ordering
         def cmpvals(x, y):
-            for field in ordering:
-                if field.startswith('-'):
-                    field = field[1:]
+            for fieldname in ordering:
+                if fieldname.startswith('-'):
+                    fieldname = fieldname[1:]
                     negate = True
                 else:
                     negate = False
-                attr = query.model._meta.get_field(field).db_column
-                attr_x = x[1].get(attr, '').lower()
-                attr_y = y[1].get(attr, '').lower()
+                field = query.model._meta.get_field(fieldname)
+                attr_x = field.from_ldap(x[1].get(field.db_column, []), connection=self.connection)
+                attr_y = field.from_ldap(y[1].get(field.db_column, []), connection=self.connection)
+                # perform case insensitive comparison
+                if hasattr(attr_x, 'lower'):
+                    attr_x = attr_x.lower()
+                if hasattr(attr_y, 'lower'):
+                    attr_y = attr_y.lower()
                 val = negate and cmp(attr_y, attr_x) or cmp(attr_x, attr_y)
                 if val:
                     return val