giolekva
giolekva

Reputation: 1178

How to create Django FormWizard for one Model?

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?

Upvotes: 2

Views: 1049

Answers (1)

Kugel
Kugel

Reputation: 19864

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.

Upvotes: 2

Related Questions