Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Enabled use of BaseInlineForm in formwizard #28

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
1 participant

When passing an inline form (generated by inlineformset_factory), formwizard would crash with a "invalid keyword: "initial") error.

inlineformset_factory produces a BaseInlineFormSet that is derived from BaseModelFormSet. Unfortunately, it needs an "initial" object as opposed to a QuerySet to be properly initialized.

A quick example of how it may be used is as follows:

recipe = Recipe.objects.get(pk=recipe_id)
initial = {
    '0':recipe.recipe_creator,
    '1':recipe,
    '2':recipe,
}
view = RecipeWizard.as_view([RecipeCreatorForm,RecipeBase, inlineformset_factory(Recipe, RecipeStep))

There is more information about inlineformset_factory here:
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/

First time I'm doing this, apologies in advance if there is any etiquette violations above. If you need anything else, please feel free to let me know so I can provide it. Thank you!

WizardView's get_form now recognizes inlineform_factory-generated forms.
(inlineforms are not passed querysets but rather a base object from which
to fetch related objects.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment