I\'m using Ben Firshman\'s fork of django-MPTT (hat tip to Daniel Roseman for the recommendation).
I\'ve got stuck trying to re-order nodes which share a common pare
I think this is an artefact of a failure in MPTT that I've mentioned before - when you move nodes around, it correctly updates the instance of the node you're moving, but it doesn't update the instance of the target (although it does get updated in the database).
The consequence of this is that in your code, each m
gets moved to the right of last_m
- but the values in the last_m
still reflect the position before the move, so the next move uses the original lft/right values instead of the new post-move ones.
The solution is to reload last_m
each time:
for id in ids:
last_m = MyModel.objects.get(pk=last_m.id)
m = MyModel.get(pk = id)
m.move_to(last_m, position='right')