I use django-mptt
application in backend and jsTree
plugin in frontend to create such tree as in the picture below in my Django project:
jsTree
plugin allows you to drag and drop nodes inside tree. django-mptt
application by default in DB create fields like: tree_id
, lft
, rght
and parent_id
. tree_id
field store information about order of nodes. parent_id
field store information about ancestor.
When user click the button after drag and drop nodes I want to save the new order of items and there new dependencies (parent_id field) in database. Сan someone say me how to make such thing?
template:
{% load mptt_tags %}
<div id="documents">
<ul>
{% recursetree documents %}
<li data-id='{{ node.tree_id }}'>
{{ node.title }}
<ul class="children">
{{ children }}
</ul>
</li>
{% endrecursetree %}
</ul>
</div>
JS:
$(function () {
$('#documents').jstree({
'plugins': ["wholerow", "dnd", "search"],
'core': {
'themes': {
'name': 'proton',
'responsive': true
},
"check_callback" : true
},
});
});