[Answer]-Folderlike group-structure with django-mptt

1👍

In user interface you can easily implement with JQuery. For example:

<div>
  <input class="parent" type="checkbox"  /> Group_1
  <ul>
    <li><input class="child" type="checkbox" />Group_1_1</li>
    <li><input class="child" type="checkbox" />Group_1_2</li>
  </ul>
</div>
<div>
  <input class="parent" type="checkbox"  /> Group_2
  <ul>
    <li><input class="child" type="checkbox" />Group_2_1</li>
    <li><input class="child" type="checkbox" />Group_2_1</li>
  </ul>
</div>
<script>
   $( document ).ready(function() {
      $('.child').click(function(){
        $(this).closest('div').find('.parent').attr('checked', true)
      });
   });
</script>

In your view you can use the same pseudocode logic:

if child_group_obj.parent:
    child_group_obj.parent.checked = True

Leave a comment