私はdjango-mptt(Ver 5.5)を使用していますdjango-mptt.github.io/django-mptt/
私は次のようなツリー構造を持っています:
+Object Oriented
|----Java
+Procedural
|----Python
|----PHP
|----B
|----C
ここで、 の親Python
とPHP
ノードをObject Oriented
に変更して、次のようにツリーを再構築したいと考えています。
+Object Oriented
|----Java
|----Python
|----PHP
+Procedural
|----B
|----C
ノードの親属性を次のように変更して、これを試しました
>>>oo=Nodes.objects.get(name='Object Oriented')
>>>py=Nodes.objects.get(name='Python')
>>>py.parent=oo
これを行った後、私は得る:
>>>py.parent==oo
True
>>>py.get_ancestors(ascending=False, include_self=False)
[<Nodes : 'Procedural'>]
次のような組み込みメソッドでさえ:
py.move_to(oo,'first-child')
私にはうまくいかないようです。
さらに明確にする必要がある場合、私のモデルは次のとおりです。
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']
親を変更する方法を教えてください。