Djangocon: Forms are not static - Markus HoltermannΒΆ

Tags: django, djangocon

(One of the summaries of a talk at the 2015 Djangocon EU conference).

Markus Holtermann works on the django core team.

Forms are basically there for input validation. They’re also used for rendering actual web forms.

Normally, forms are pretty static. The field are there and they don’t change. But sometimes you want for instance request dependent forms. Depending on the request, some fields might be left out or are added. The same way, depending on the permissions of the user, there might be more or fewer values in a dropdown. Markus would say that those forms are still static, because you have to write code to make those kind of changes.

He was involved with a website that dealt with different events. Every event needed a form with slightly different fields. With regular static forms, you’d need to create a fresh new form class a couple of times a year. Not nice.

He ended up making django-dynamic-forms that could construct forms on the fly.

Django itself dynamically creates forms when you use ModelForms. It reads the model and dynamically creates a class. You can do that in python with type().

He does basically the same, but he doesn’t read a fixed Model. Instead django-dynamic-forms forms are defined in the database. There is a “Form” model and a “FormField” model. With this, you can create forms via the django admin. There are some actions you can add to the form, like a mail action. Fields can be configured with help text, form field length, min/max values, etc.

(It reminds me a lot of PloneFormGen which did something like this for Plone, a Python CMS. I worked on that 6 years ago or so :-) Such a product is VERY useful. )

Photo from our 2014 cycling holiday
blog comments powered by Disqus logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):