我得到以下代码以递归方式将数据从旧表迁移到 MPTT
def traverse_design_idea(parent_id=1, parent=None):
for _cat in OldTablefilter(parent=parent_id):
cat = DesignCategory(name=_cat.category, old_id=_cat.sbt_id, parent=parent)
cat.save()
traverse_design_idea(_cat.sbt_id, cat)
traverse_design_idea()
cat = DesignCategory.objects.get(pk=100)
cat.get_ancestors() //give wrong parents
关系设置正确,但 get_ancestors() 提供错误信息,我已阅读有关更新父节点的信息,但无法使其正常工作。