2

How can I do a nested multi select tree using django model form and the select tree will have more than 400 items

I've been searching on the internet but I didn't find something suitable for this problem, Does anyone has a tutorial that I can read ?

thanks in advance.

This is my model

class CNPQ(models.Model):
    title = models.CharField(verbose_name="Nome da Área de conhecimento", max_length=255, blank=True, null=True)
    description = models.CharField(verbose_name="Descrição da Área de conhecimento" ,max_length=255, blank=True, null=True)
    level  = models.TextField(verbose_name="Nível")
    created = models.DateTimeField(auto_now_add=True)
    parent = models.ForeignKey('self', null=True, on_delete=models.CASCADE)

what I want is to do this but using django and jquery

enter image description here

based in the level from my table

enter image description here

Diogo Silva
  • 195
  • 3
  • 17
  • What do you mean by nested tree ? What values will you choose between, other models ? – May.D May 22 '18 at 12:49
  • sorry for my explanation, I'm using just one table to create an tree and it will have levels that will identify if the items are parent or siblings. I was trying this https://github.com/patosai/tree-multiselect.js?utm_source=recordnotfound.com but I got a problem with data-section, I could not add data section with a specific name to make it nested – Diogo Silva May 22 '18 at 13:00

1 Answers1

2

To add data-section attribute to your options, you'll need to override the create_option() method of the Select widget in your ModelForm. More documentation about this here and here.

May.D
  • 1,832
  • 1
  • 18
  • 34