Skip to main content

A dynamic JSON-based form engine for Django

Project description

e3-django-dynamic-forms

A dynamic JSON-based form engine for Django. Staff design form schemas via a visual web UI, those schemas render server-side as Django forms, and responses are stored as JSON.

Installation

pip install e3-django-dynamic-forms

Quick Setup

  1. Add to INSTALLED_APPS:
INSTALLED_APPS = [
    # ...
    'rest_framework',
    'dynamic_forms',
]
  1. Include URLs:
urlpatterns = [
    path('dynamic-forms/', include('dynamic_forms.urls')),
]
  1. Run migrations:
python manage.py migrate
  1. Visit /dynamic-forms/schemas/ to start designing forms.

Templates

The package ships with a built-in base template (dynamic_forms/base.html) so it works out of the box — no need to provide your own base.html.

To use your project's base template instead, set BASE_TEMPLATE in your settings:

DYNAMIC_FORMS = {
    'BASE_TEMPLATE': 'my_project/base.html',
}

The only requirement is that your base template defines a {% block content %} block, which is where all dynamic form pages render their content.

Settings

All settings go in a DYNAMIC_FORMS dict in your Django settings:

DYNAMIC_FORMS = {
    'BASE_TEMPLATE': 'dynamic_forms/base.html',       # Template to extend (default: built-in)
    'FIELD_AGENT_CHECK': 'myapp.utils.is_agent',      # Custom field agent check
    'USER_ADMIN_UNIT': 'myapp.utils.get_admin_unit',   # Custom admin unit getter
    'ADMIN_UNIT_MODEL': 'myapp.AdminUnit',             # Admin unit model (optional)
    'STAFF_PERMISSION_MIXIN': 'dynamic_forms.permissions.IsStaffMemberMixin',
    'FIELD_AGENT_PERMISSION_MIXIN': 'dynamic_forms.permissions.IsFieldAgentUserMixin',
}

Swappable Attachment Model

Like AUTH_USER_MODEL, you can swap the attachment model:

# settings.py
DYNAMIC_FORMS_ATTACHMENT_MODEL = 'myapp.MyAttachment'
# myapp/models.py
from dynamic_forms.models import AbstractAttachment

class MyAttachment(AbstractAttachment):
    extra_field = models.CharField(max_length=255)

    class Meta(AbstractAttachment.Meta):
        swappable = 'DYNAMIC_FORMS_ATTACHMENT_MODEL'

JSON Schema Format

{
    "pages": [
        {
            "title": "Page 1",
            "fields": [
                {
                    "name": "field_name",
                    "type": "string",
                    "label": "Field Label",
                    "required": true,
                    "help_text": "Help text",
                    "order": 0,
                    "validators": {"min_length": 2, "max_length": 100},
                    "enum": ["opt1", "opt2"],
                    "multi": false,
                    "conditions": {
                        "logic": "AND",
                        "rules": [
                            {"field": "other_field", "operator": "equals", "value": "yes"}
                        ]
                    }
                }
            ]
        }
    ]
}

Supported Field Types

Type Description Validators
string Text input min_length, max_length
number Float input min_value, max_value
integer Integer input min_value, max_value
boolean Checkbox
date Date picker min_value, max_value (supports "today")
file File upload
geolocation GPS capture button

Add "enum": [...] to string for dropdown, plus "multi": true for checkboxes.

Condition Operators

equals, not_equals, contains, greater_than, less_than, between (format: "min,max")

API Endpoints

  • GET/POST /dynamic-forms/api/form-schemas/ — List/create schemas (staff only)
  • GET/PUT/DELETE /dynamic-forms/api/form-schemas/<uuid>/ — Schema detail (staff only)
  • GET/POST /dynamic-forms/api/form-responses/ — List (staff) / create (authenticated)
  • GET /dynamic-forms/api/form-responses/<uuid>/ — Response detail (staff only)
  • Filter responses: ?schema=<uuid>

Development

pip install -e ".[dev]"
pytest tests/ -v

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

e3_django_dynamic_forms-0.1.2.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

e3_django_dynamic_forms-0.1.2-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file e3_django_dynamic_forms-0.1.2.tar.gz.

File metadata

  • Download URL: e3_django_dynamic_forms-0.1.2.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for e3_django_dynamic_forms-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a924a92d4d5cd9a6dd6b6cf1e45954ff5e156d3d66e448423d8580286be6bced
MD5 8a9cd865d6f3d893193fae322efe6115
BLAKE2b-256 eabfb5e476ddb37e29b4ace4a845b786d5b7eb0f90d781130f0e203dedf9c92e

See more details on using hashes here.

File details

Details for the file e3_django_dynamic_forms-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for e3_django_dynamic_forms-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f560a24ffe9da9ea7cdcda9db5489a84106308cbbdfc3bd3960c273a27e9cafd
MD5 4e01b85c30b07c25efdb155e5a3b4e37
BLAKE2b-256 441504b51047ccd0c5b3d0422f6f84b658fbdb29aa5d09a8376777fe4631184b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page