| Issue 35: | How can I regenerate the hidden fields value having only the parent_id? | |
| 2 people starred this issue and may be notified of changes. | Back to list |
Hello, I have to migrate a hierarchy from another PHP project and I want to use Django mptt. I have an ID and a Parent ID. I insert the data into the data base with "lft", "rght", "level", "tree_id" set to 0. (Via SQL inserts) How can I regenerate correct values for the hidden fields? If I go into the admin, edit my Category object these values stay to 0. Does mppt have a magic method that regenerate the all tree in database? How can I do that? Thy a lot for you help, Batiste Bieler
Nov 27, 2008
In fact I was wrong, it's not working: >>> category.get_descendants() [] >>> category.children.all() [<Category: cat1>, ..., <Category: cat6>] Any idea how to fix that?
Dec 5, 2008
Patch in issue#13 (by me) adds a magic Model.tree.rebuild() method for you :).
Dec 5, 2008
Hey man, thanks lot!
Sep 2, 2010
(No comment was entered for this change.)
Status:
Verified
|
It seems that simply save my model again do the trick... Thx for mptt from myapp.models import Category c = Category(id=0, order=1).save() for c in Category.objects.all(): if c.parent_id == 0: c.parent = None c.save() c.delete()