Thursday, January 2, 2014

How to approach this problem?

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 | |
|             +-------------------+ |
+-----------------------------------+

Please, any kind of help, suggestion or link will be very appreciated :-)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0f74890d-0271-4614-98c3-311cfbdcd635%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment