I'm trying to solve a problem, but I have no idea how to face it. I need some help :-)
I have a model hierarchy like this:
class Task(models.Model):
name = models.CharField(max_length=255)
number_of_steps = models.IntegerField()
class StepGroup(models.Model):
task = models.ForeignKey(Task)
init_date = models.DateField()
class Step(models.Model):
group = models.ForeignKey(StepGroup)
name = models.CharField(max_length=255)
I must write a dialog where I create a number of Step Groups. An InlineFormSet looks the way to go, but as there are two levels of nesting, I don't know how to do that.
Besides, I need the usual stuff with forms: error control (form.name_of_field.errors), autopopulation when editing the Task, etc, so doing it manually with javascript and server-side handling of the POST request would be too complicated and error-prone.
This is the way I need the form (the number of steps in each group is set by the "number_of_steps" field in the Task model):
+-----------------------------------+
| STEP GROUP 1 |
| |
| Init date: _____________ |
| |
| Step 1: ________________ |
| Step 2: ________________ |
| Step 3: ________________ |
| |
+-----------------------------------+
| STEP GROUP 2 |
| |
| Init date: _____________ |
| |
| Step 1: ________________ |
| Step 2: ________________ |
| Step 3: ________________ |
| |
+-----------------------------------+
| |
| +-------------------+ |
| | Create step group | |
| +-------------------+ |
+-----------------------------------+