views:

176

answers:

1

I have Django Model with many fields which user must fill. If I'll create one ModelForm for this Model it will be big enough for one form. I want to split it using FormWizard. I think it's possible first to create forms dynamically and then create FormWizard using them.

Is this good approach or is there any better way?

+1  A: 

To me it seems fine.

The approach for creating partial forms is written in the docs.

In short:

class PartialAuthorForm(ModelForm):
    class Meta:
        model = Author
        fields = ('name', 'title')

class PartialAuthorForm(ModelForm):
    class Meta:
        model = Author
        exclude = ('birth_date',)

Dynamic way of doing this would be:

def gimme_my_form(field_tuple):
    class MyForm(ModelForm):
        class Meta:
            model = MyModel
            fields = field_tuple
    return MyForm

Eventually you can also parametrize the model this way.

Kugel
Nope, I don't like that. It's not ok for my model, there would be at least 4 tabs each containing 10 (average) fields.
giolekva
What is wrong with that? Please, specify what usage would you like. Then we can come up with a suiting approach.
Kugel
OK I just realized you want a dynamic way, I edited my answer.
Kugel
I've found same approach
giolekva