N
N
nurzhannogerbek2017-05-12 18:52:14
Django
nurzhannogerbek, 2017-05-12 18:52:14

How to create a tree view with checkbox?

Hello! Please help me figure it out.
There is a Program model with a function field that has a ManyToManyField data type. I need to create a form where the user could add functions for the program, like in the picture below. In other words, a tree-like list with the ability to open and close and checkboxes. I found the django-mptt application , which, as I understand it, makes it possible to create tree structures. Should I use this application for my needs or not? Does this application provide flexible settings in the template (In my case, checkboxes are needed for functions)? Can someone who has already worked with this application show a good example, because I can not fully understand the concept of this application.
cd519643e76d4756ad6f697965a7e8bd.jpg
models.py:

class Group(models.Model):
    name = models.CharField(_('Name'), max_length=250)

class Task(models.Model):
    name = models.CharField(_('Name'), max_length=250)
    group = models.ForeignKey(Group, on_delete=models.CASCADE)

class Function(models.Model):
     name = models.CharField(_('Name'), max_length=250)
     task = models.ForeignKey(Task, on_delete=models.CASCADE)

class Program(models.Model):
    name = models.CharField(_('Name'), max_length=250)
    function = models.ManyToManyField("Function")

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question