moberley  committed 76bff51

Modify changelist ordering methods to be compatible with Django 1.4.

Django 1.4 handles changelist sorting differently and consequently the
get_ordering() method returns a list of ordering fields instead of the single
(order_field, order_type) tuple from earlier versions.

If the superclass get_ordering() method does not return a list this revised
method will work as before, i.e. the default ('id', 'desc') will be changed to
(None, 'asc'). Otherwise the superclass get_ordering() return value will be
passed through.

  • Participants
  • Parent commits 0e72103
  • Branches default

Comments (0)

Files changed (1)

File treebeard/

 class TreeChangeList(ChangeList):
-    def get_ordering(self):
+    def get_ordering(self, *args):
-        Overriding default's ChangeList.get_ordering so we don't sort the
-        results by '-id' as default
+        Overriding ChangeList.get_ordering if using the Django version <= 1.3
+        default of '-id' but passing through the >= 1.4 default of '[]'.
-        if not check_empty_dict(self.params):
-            return super(TreeChangeList, self).get_ordering()
-        return None, 'asc'
+        ordering = super(TreeChangeList, self).get_ordering(*args)
+        if type(ordering) != type([]):
+            if not check_empty_dict(self.params):
+                return ordering
+            else:
+                return None, 'asc'
+        return ordering
 class TreeAdmin(admin.ModelAdmin):
     change_list_template = 'admin/tree_change_list.html'
     form = MoveNodeForm
-    def get_changelist(self, request):
+    def get_changelist(self, request, **kwargs):
         return TreeChangeList
     def queryset(self, request):