7

I m using django-mptt (Ver 5.5) django-mptt.github.io/django-mptt/

I have a tree structure as:

+Object Oriented
|----Java
+Procedural
|----Python
|----PHP
|----B
|----C

now i want to restructure the tree , by changing the parent of Python and PHP node to Object Oriented, to look as:

 +Object Oriented
|----Java
|----Python
|----PHP
+Procedural
|----B
|----C

i have tried this by changing the parent attribute of node as

>>>oo=Nodes.objects.get(name='Object Oriented')
>>>py=Nodes.objects.get(name='Python')
>>>py.parent=oo

After doing this i get:

>>>py.parent==oo
True
>>>py.get_ancestors(ascending=False, include_self=False)
[<Nodes : 'Procedural'>]

Even the inbuilt-methods such as:

py.move_to(oo,'first-child')

doesn't seems to work for me.

if more clarification is required my model is:

from django.db import models
from mptt.models import MPTTModel, TreeForeignKey

class Nodes(MPTTModel):
    name = models.CharField(max_length=50, unique=True)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')

    def __unicode__(self):
        return self.name

    class MPTTMeta:
        order_insertion_by = ['name']

kindly tell me a way to change the parent.

akm
  • 79
  • 2

0 Answers0