The .move_to () method does not work for me. I looked at other posts that people recommend keeping the instance as well as reloading the node instances. But none of these solutions work in this case. I also tried to do ._tree_manager.rebuild (), which also does not work. My test code is below:
def test_reorder_pages(self):
p = Page.objects.get(slug='page-1')
p2 = Page.objects.get(slug='page-2')
self.assertEqual(1, p.lft)
self.assertEqual(3, p2.lft)
p2.move_to(p, 'left')
p = Page.objects.get(slug='page-1')
p2 = Page.objects.get(slug='page-2')
self.assertEqual(3, p.lft)
self.assertEqual(1, p2.lft)
Basically, I expect page-2 to fit "to" (to the left of ...) page-1. But the last two statements fail. I also checked all the other values (lft, rght, level, tree_id), and none of them changed.
Does anyone know what I'm doing wrong?
EDIT: mossplix page.tree.rebuild(). , .
move_to() :
self.assertEqual(0, p.level)
self.assertEqual(1, p.lft)
self.assertEqual(2, p.rght)
self.assertEqual(1, p.tree_id)
self.assertEqual(0, p2.level)
self.assertEqual(3, p2.lft)
self.assertEqual(4, p2.rght)
self.assertEqual(1, p.tree_id)
move_to() rebuild(), , :
self.assertEqual(0, np.level)
self.assertEqual(3, np.lft)
self.assertEqual(4, np.rght)
self.assertEqual(1, p.tree_id)
self.assertEqual(0, np2.level)
self.assertEqual(1, np2.lft)
self.assertEqual(2, np2.rght)
self.assertEqual(1, p.tree_id)
, (lft, rght, level, tree_id). , , ?
:
, - . , , , . TransactionTestCase, . , , .