Dynamic nested forms in Django

I saw several blog posts (e.g. one from yergler) about this, but couldn't find a nice elegant solution.

I have 3 models:

class Workflow(models.Model): 
    name = models.CharField(max_length=255) 
    company = models.ForeignKey(Company) 
    class Meta: 
        unique_together = ('name', 'company') 
class Milestone(models.Model): 
    workflow = models.ForeignKey(Workflow) 
    tasks = models.ManyToManyField(Task) 
class Task(models.Model): 
    task = models.CharField(max_length=255) 

How can I create a form that allows me to add many steps to the workflow and many milestone tasks?

Basically, I want to give them a create form or an edit form and let them create a workflow with milestones and tasks, but would like to let them dynamically add them using javascript.

The dynamic / javascript part is simple, but I could not figure out how to insert a form set inside a form set. that is, Tasks under the milestone.

+3
source share
1 answer

, , formset , NestedFormset, , , - ..

1.title => "Milestone 1 title"
2.title => "Milestone 2 title"
1.1.task => "Task for milestone 1"
1.2.task => "Task for milestone 2"

, , Formset- github, : P , Formset , , - , .

0

All Articles