Has anyone tried using wagtail form builder in a django project?

166 views
Skip to first unread message

Ben Wattie

unread,
Aug 23, 2016, 12:58:00 AM8/23/16
to Wagtail support
I've got a long standing project, from before wagtail, which I'd love to migrate completely to wagtail, but that would be a lot of effort. It's currently django 1.9

A form builder, like wagtailforms would be a very nice addition, as there is nothing up to that standard for pure django that I know of.

What steps would I need to get it to work in django? Any classes that won't work without wagtail and or functionality I need to duplicate?

Would it be too much work to justify?

Serafeim Papastefanos

unread,
Aug 23, 2016, 2:41:43 AM8/23/16
to wag...@googlegroups.com
Hello Ben,

most of the functionality of the wagtail form builder can be found on
wagtail/wagtailforms/{forms, models}.py. In forms.py you'll find a
FormBuilder object (not related to other wagtail classes) that can be
initialized with an array of fields and return a normal django Form.
Each field in that array of fields is just an instance of an
AbstractFormField (found in models.py) that has some specific
attributes like label, field_type, required etc. This
AbstractFormField does actually need wagtail because it inherits from
Orderable (to allow it to be ordered in the wagtail editor) but you
can instead just inherit from models.Model.

So, each of your dynamic forms should contain an array of
AbstractFormFields (you'll need *another* form through which you'll
create these fields) and, when you want to display it you'll pass that
array of fields to the FormBuilder and you'll get back your form to
put in your view.

Also, before a couple of years I had written an article that should
explain these concepts some more:
https://spapas.github.io/2013/12/24/django-dynamic-forms/. In there I
had a JSON string as a source of the dynamic form (I hadn't create a
normal form for creating the dynamic form, instead I just allowed the
editors to edit the JSON directly through the /admin) -- but that JSON
could instead be database fields like in wagtail.

Best regards,
Serafeim
> --
> You received this message because you are subscribed to the Google Groups
> "Wagtail support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wagtail+u...@googlegroups.com.
> To post to this group, send email to wag...@googlegroups.com.
> Visit this group at https://groups.google.com/group/wagtail.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/wagtail/a9f45a4a-e76f-4c07-9f63-a2194a691a86%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ben W

unread,
Aug 23, 2016, 7:30:25 PM8/23/16
to wag...@googlegroups.com
Hi Serafeim

Thanks for your response.
Will give it a go!


> To post to this group, send email to wag...@googlegroups.com.
> Visit this group at https://groups.google.com/group/wagtail.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/wagtail/a9f45a4a-e76f-4c07-9f63-a2194a691a86%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Wagtail support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wagtail/2hytclJzv7Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wagtail+unsubscribe@googlegroups.com.
To post to this group, send an email to wag...@googlegroups.com.

keepingtrc...@gmail.com

unread,
Sep 3, 2016, 2:08:58 PM9/3/16
to Wagtail support
hello Serafeim,

would you mind clarifying "(you'll need *another* form through which you'll create these fields)"?  I'm having difficulty rendering
form fields in the template.  Everything's been configured, as per documentation, and I'm still not having any luck producing
any form fields.  I can, however, access fields from the 'AbstractForm/Page'.  It appears the 'form' var passed to the template
is empty.

thanks

keepingtrc...@gmail.com

unread,
Sep 3, 2016, 2:31:55 PM9/3/16
to Wagtail support
Serafeim,

i've solved my issue
Reply all
Reply to author
Forward
0 new messages