1

I am trying to use django-treebeard to manipulate hierarchical data with postgresql as the database. My current versions are :

Django==3.0.4
django-treebeard==4.3.1
djangorestframework==3.11.0

So, the bug occurs when I make a node a child of another one, then set again the child node as a root node. The view method that is responsible for moving the nodes is the following :

# Change a process's parent
@action(detail=True, methods=['patch'])
def change_parent(self, request, pk=True):
    process = Process.objects.get(pk=pk)
    print('current process ' + process.title)

    data = request.data
    if 'parent' in data:
        new_parent_pk = data['parent']

        if(new_parent_pk == 0):
            process.move(process.get_root())
            process.save()

        elif(new_parent_pk > 0):
            new_parent = Process.objects.get(pk=new_parent_pk)
            process.move(new_parent, 'first-child')
            process = Process.objects.get(pk=pk)
            process.save()

Also, this fails at the first try when the moved node has children. I've read that people concluded that this has something to do with the database chosen collation.

  • If this is the reason of the bug, what is the best configuration for postgres to work with django-treebeard?
  • Otherwise what could be the problem (the used code is matching the one coming in treebeard admin logic file)?
  • Also, is there any replacements for django-treebeard ?
Mehdi Fracso
  • 448
  • 2
  • 16

0 Answers0