Skip to content

Is it possible to pass parameter to a form __init__ in a collection? #93

Answered by boosh
lallulli asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, I've just discovered I can reach into the holder dict. This works:


class WizardView(FormCollectionView):
    template_name = "core/wizards/create.html"
    collection_class = WizardForm
    success_url = "/"

    def get_collection_kwargs(self):
        kwargs = super().get_collection_kwargs()
        kwargs["project"] = get_current_project(self.request)
        return kwargs


class WizardForm(FormCollection):
    default_renderer = FormRenderer(
        field_css_classes="mb-3",
        fieldset_css_classes="border-2 rounded p-3 mb-3",
    )
    main_form = MainForm()
    blog_post = BlogPostForm()

    def __init__(self, *args, **kwargs):
        project = kwargs.pop('project')
  …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@boosh
Comment options

@boosh
Comment options

Answer selected by jrief
Comment options

You must be logged in to vote
2 replies
@jrief
Comment options

@nicokant
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #92 on October 13, 2023 13:59.