Package: django-jsonsuit
django-jsonsuitDjango goodies to dress JSON data in a suit.DocumentationThe full documentation is athttps://tooreht.github.io/django-jsonsuit.An example project can be found athttps://github.com/tooreht/django-jsonsuit-example.FeaturesEditable and readonly widgetChange JSON syntax highlighter themesSet custom widget media (JS & CSS) filesUse custom HTML templatesQuickstartInstall django-jsonsuit:pip install django-jsonsuitAdd it to yourINSTALLED_APPS:INSTALLED_APPS = (
    ...
    'jsonsuit.apps.JSONSuitConfig',
    ...
)UsageWidgetsdjango-jsonsuit currently provides two widgets to dress your JSON data:JSONSuit: Widget that displays JSON data with indentation and syntax highlighting as default, but allows to toggle between the standard djangoTextareafor editing.ReadonlyJSONSuit: Widget that simply displays JSON data with indentation and syntax highlighting. It is useful for JSON fields that contain readonly data.Note: Because a widget in django is only responsible for displaying fields, it has no direct access to its field properties. Thus there is no easy way to check if the field is readonly. The readonly behaviour is even handled differently among django forms, model forms and admin. This is why theReadonlyJSONSuitwas introduced.Note: When using multiple form instances or multiple forms with equal field names on the same page useFormsetsorprefixesto avoid HTML element id clashes.JSONSuitIn a form or model admin, enable a JSON suit for a particular field:fromjsonsuit.widgetsimportJSONSuitclassJSONForm(forms.ModelForm):classMeta:model=Testfields='__all__'widgets={'myjsonfield':JSONSuit(),}classJSONAdmin(admin.ModelAdmin):form=JSONFormEnable JSON suit for every JSONField of a model:fromdjango.dbimportmodelsclassJSONAdmin(admin.ModelAdmin):formfield_overrides={models.JSONField:{'widget':JSONSuit}}ReadonlyJSONSuitIn a form or model admin, enable a readonly JSON suit for a particular field:fromjsonsuit.widgetsimportReadonlyJSONSuitclassReadonlyJSONForm(forms.ModelForm):classMeta:model=Testfields='__all__'widgets={'myjsonfield':ReadonlyJSONSuit(),}classReadonlyJSONAdmin(admin.ModelAdmin):form=ReadonlyJSONFormEnable readonly JSON suit for every JSONField of a model:fromdjango.dbimportmodelsclassReadonlyJSONAdmin(admin.ModelAdmin):formfield_overrides={models.JSONField:{'widget':ReadonlyJSONSuit}}Template TagsUse the jsonsuit template tag to display serializable objects in templates. Note that in order to use thejsonsuit,jsonsuit_cssandjsonsuit_jstags, they must be loaded using{% load jsonsuit %}.{% extends "ui/base.html" %}
{% load jsonsuit %}

{% block title %}{% trans "JSONSuit Template Tag" %}{% endblock %}

{% block styles %}
    {{ block.super }}
    {% jsonsuit_css %}<!-- include jsonsuit CSS files -->{% endblock %}

{% block content %}<divclass="row"><divclass="col-md-4"><h2>Unnamed Suit</h2>{% jsonsuit data %}<!-- with no parameter supplied,a uuid is generated asHTML attribute value toidentify each individual suit:data-jsonsuit="<uuid>" --></div><divclass="col-md-8"><h2>Named Suit</h2>{% jsonsuit data 'suit_name' %}<!-- for each suit,an optional stringcan be supplied, whichserves as HTML attributevalue: data-jsonsuit="<suit_name>" --></div></div>{% endblock %}

{% block scripts %}
    {{ block.super }}
    {% jsonsuit_js %}<!-- include jsonsuit JS files -->{% endblock %}ThemeSet JSON syntax highlighter theme in settings:JSONSUIT_WIDGET_THEME='twilight'Available themes:coy,dark,default,funky,okaidia,solarizedlight,twilight,tomorrow. Defaults to thedefaulttheme.Custom Widget MediaSet custom widget media (JS & CSS) files:JSONSUIT_WIDGET_MEDIA_JS=('jsonsuit/js/mysyntaxhighlighter.js','jsonsuit/js/myscripts.js')JSONSUIT_WIDGET_MEDIA_CSS={'all':('jsonsuit/css/mytheme.css','jsonsuit/css/mystyles.css')}JSONSUIT_READONLY_WIDGET_MEDIA_JS=('jsonsuit/js/mysyntaxhighlighter.js','jsonsuit/js/myreadonlyscripts.js')JSONSUIT_READONLY_WIDGET_MEDIA_CSS={'all':('jsonsuit/css/mytheme.css','jsonsuit/css/myreadonlystyles.css')}To only replace the syntax highlighter assets for all widgets, simply change:JSONSUIT_SYNTAX_HIGHLIGHTER_JS=('jsonsuit/js/mysyntaxhighlighter.js',)JSONSUIT_SYNTAX_HIGHLIGHTER_CSS=('jsonsuit/css/mytheme.css',)Custom HTML templateOverridejsonsuit/widget.htmlorjsonsuit/readonly_widget.htmltemplate:jsonsuit/templates
└──jsonsuit└──widget.html└──readonly_widget.htmlRunning TestsDoes the code actually work?source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ toxDevelopment commandspip install -r requirements_dev.txt
invoke -lCreditsProject dependencies:prismvanilla-jsProject documentation:MkDocsTools used in rendering this package:Cookiecuttercookiecutter-djangopackageZest.releaser