Skip to main content

A widget for the Django JSONFIELD, this widget usefulness is to have dynamic fields for a given model.

Project description

Installation

Install the package with pip install django_jsonfield_widget

Then add it to the INSTALLED_APPS in settings.py :

INSTALLED_APPS = [
    '...',

    'django_jsonfield_widget',

    '...'
]

JsonFieldSchemaWidget

The JsonFieldSchemaWidget is a widget that adds a fixed schema to the json. The Json is blocked in this canvas and cannot be adapted by the enduser when this widget is used. This widget was developped to create dynamic form schemas where the dynamic fields are controlled by python code

To use the JsonFieldSchemaWidget in a form do:

from django_jsonfield_widget.widgets import JsonFieldSchemaWidget
from collections import OrderedDict

class SomeForm(forms.ModelForm):
    class Meta:
        model = SomeModel
        fields = '__all__'
        widgets = {
            'json_field': JsonFieldSchemaWidget(schema=OrderedDict({
                'height': {
                    'verbose_name': 'What is your height in cm?',
                    'type': 'IntegerField'
                },
                'name': {
                    'verbose_name': 'What is your name?',
                    'type': 'CharField',
                },
                'has_freckless': {
                    'verbose_name': 'Do you have freckless?',
                    'type': 'BooleanField',
                }
            })),
        }
jsonfield schema widget example

JsonFieldSchemaWidget layout for the above settings.

About

developped by : DEUSE - Développement Software

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

django_jsonfield_widget-0.1.0.tar.gz (82.2 kB view hashes)

Uploaded Source

Supported by

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