Welcome to django-dynamic-fields documentation!


https://img.shields.io/pypi/dm/django-dynamic-fields.svg https://secure.travis-ci.org/yourlabs/django-dynamic-fields.png?branch=master https://codecov.io/github/yourlabs/django-dynamic-fields/coverage.svg?branch=master Documentation status

This app provides features a form class dynamic, both on the client and server side. For example if you want a field to be remove if another field has a particular value or to filter choices based on a set conditions. The demo is automatically updated when a commit is tested on master.

Pypy, Python 2.7, 3.4, Django 1.8+ are supported.


For example, if your form should allow support only if linux is selected:

from ddf import shortcuts as ddf

class TestForm(ddf.FormMixin, forms.Form):
    platform = forms.ChoiceField(choices=(
        ('Linux', 'Linux'),
        ('BSD', 'BSD'),
        ('Windows', 'Windows'),
    service = forms.ChoiceField(choices=(
        ('Setup', 'Setup'),
        ('Support', 'Support')

    _ddf = dict(
        # List of Actions to execute on the service field
            # Remove the service field
                # If platform field is Windows
                ddf.ValueIs('platform', 'Windows'),
            # Remove a list of choices from the service field
                ['Support'], # That's the list of choices to remove
                # If platform field value is Windows
                ddf.ValueIs('platform', 'BSD'),

This example will cause the “service” field to be removed when the user selects platform=Windows. If the user selects BSD, then it will just remove the Support choice from the service field.

The configuration field is able to render the configuration as a JSON dict, with the form prefix it’s being rendered with. Then, the equivalent of each Action and Condition objects are instanciated in JavaScript, allowing dynamic user experience.

A configuration is structured as such: for each field, you may add a list of actions, for each action a list of conditions. When the user changes a field, each action’s conditions are evaluated and if they all pass then the action is applied, otherwise it is unapplied. Possibilities are huge here.


It is released with the Creative Commons Attribution-NonCommercial 3.0 Unported License, but a commercial license is available, please get in touch with the author by email (see setup.py) if you are interrested.

Note that the money goes to YourLabs, a non-profit foundation to promote the role of hackers in the process of making our society more fair and free, while using their skills to develop local economy and give internet back to the people.


The project is pretty young, but the basic building blocks are there. We should be able to add actions and conditions easily.


We’ve been inventing this over and over again for years. The first time I invented this was in 2009 and honnestly my python, django and javascript skills were pretty weak back then. Since then, I’ve seen users asking this, paying me as a consultant for this, making pull requests to have this in a per-app basis. It’s about time we have a generic solution that works for all kinds of fields, and not just the ones of the apps we maintain.

Indices and tables