sitetree/admin.py
def item_move(self, request, tree_id, item_id, direction):
        """Moves item up or down by swapping 'sort_order' field values of neighboring items."""
        current_item = MODEL_TREE_ITEM_CLASS._default_manager.get(pk=item_id)
        if direction == 'up':
            sort_order = 'sort_order'
        else:
            sort_order = '-sort_order'

        siblings = MODEL_TREE_ITEM_CLASS._default_manager.filter(
            parent=current_item.parent,
            tree=current_item.tree
        ).order_by(sort_order)

        previous_item = None
        for item in siblings:
            if item != current_item:
                previous_item = item
            else:
                break

        if previous_item is not None:
            current_item_sort_order = current_item.sort_order
            previous_item_sort_order = previous_item.sort_order

            current_item.sort_order = previous_item_sort_order
            previous_item.sort_order = current_item_sort_order

            current_item.save()
            previous_item.save()

        return HttpResponseRedirect('../../')
def item_move(self, request, tree_id, item_id, direction):
        current_item = MODEL_TREE_ITEM_CLASS._default_manager.get(pk=item_id)
        if direction == 'up':
            sort_order = 'sort_order'
        else:
            sort_order = '-sort_order'

        siblings = MODEL_TREE_ITEM_CLASS._default_manager.filter(
            parent=current_item.parent,
            tree=current_item.tree
        ).order_by(sort_order)

        previous_item = None
        for item in siblings:
            if item != current_item:
                previous_item = item
            else:
                break

        if previous_item is not None:
            current_item_sort_order = current_item.sort_order
            previous_item_sort_order = previous_item.sort_order

            current_item.sort_order = previous_item_sort_order
            previous_item.sort_order = current_item_sort_order

            current_item.save()
            previous_item.save()

        return HttpResponseRedirect('../../')
def item_move ( self , request , tree_id , item_id , direction ) : current_item = MODEL_TREE_ITEM_CLASS . _default_manager . get ( pk = item_id ) if direction == 'up' : sort_order = 'sort_order' else : sort_order = '-sort_order' siblings = MODEL_TREE_ITEM_CLASS . _default_manager . filter ( parent = current_item . parent , tree = current_item . tree ) . order_by ( sort_order ) previous_item = None for item in siblings : if item != current_item : previous_item = item else : break if previous_item is not None : current_item_sort_order = current_item . sort_order previous_item_sort_order = previous_item . sort_order current_item . sort_order = previous_item_sort_order previous_item . sort_order = current_item_sort_order current_item . save ( ) previous_item . save ( ) return HttpResponseRedirect ( '../../' )
Moves item up or down by swapping 'sort_order' field values of neighboring items.
Moves item up or down by swapping sort_order field values of neighboring items .