Better JSON Widget for Django Admin
Project description
django-better-json-widget
Better JSON Widget for Django Admin
Features
- Better Json widget with schema for your Django Admin site
- Can watch for changes in the given field (
follow_field
) and dynamically update the JSON schema - Supports JSON Schema
- You can edit generated UI fields specified in schema or edit raw JSON
- Use Vue.js for UI
- Supports Python 3.8+ and Django 3.2+
Limitations
- Supports only a small subset of the JSON Schema (integer, number, boolean, string types)
- Does not support enum, list (yet) and object (not planned) types
So, PR's are welcome!
Installation
Install package
pip install django-better-json-widget
Add better_json_widget
to your INSTALLED_APPS
Example
from better_json_widget.widgets import BetterJsonWidget
from django.contrib import admin
from django.forms import ModelForm
from .models import TestModel
schema_mapping = {
"animal": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"limbs": {
"type": "integer",
"title": "Number of limbs",
"description": "How many limbs does the animal have?",
},
"color": {"type": "string", "title": "Color"},
"herbivore": {
"type": "boolean",
"title": "Is it herbivore?",
"default": True,
},
},
"required": ["limbs", "herbivore"],
},
"superhero": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Name",
"description": "Give a name to your superhero",
},
"superpower": {"type": "string"},
},
"required": ["name"],
},
}
class TestModelAdminForm(ModelForm):
class Meta:
model = TestModel
fields = "__all__"
widgets = {
"options": BetterJsonWidget(
follow_field="type",
# `schema_mapping` and `schema` can be callables
schema_mapping=schema_mapping,
),
}
@admin.register(TestModel)
class TestModelAdmin(admin.ModelAdmin):
form = TestModelAdminForm
fields = [
"type",
"options", # JsonField
]
Also, if you don't need to dynamically change schema, you can use schema
option:
BetterJsonWidget(
schema={
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
...
},
"required": [],
},
)
Settings
If for some reason you don't want to use bundled Vue.js, you can use BETTER_JSON_WIDGET_VUE_ESM_URL
settings:
BETTER_JSON_WIDGET_VUE_ESM_URL = "https://unpkg.com/vue@3/dist/vue.esm-browser.js"
License
Credits
This project was generated with yakimka/cookiecutter-pyproject
.
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
Built Distribution
Close
Hashes for django-better-json-widget-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ed897ebcbe35cca71bc7fb7813f9d97c78ad1e2040d681b295e54547a90d237 |
|
MD5 | c3a02871c6e35bdfa90c567b34fb35db |
|
BLAKE2b-256 | e73afa47ef86c558017c18787a39204db0bcef35d53494ce43b297a72f003f4b |
Close
Hashes for django_better_json_widget-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb576b46c648fff336e45dae6df5713d204e697d85e541cb0a204b7aa1aca21d |
|
MD5 | cc2b117dc924ad65c6adc93216b3a7d6 |
|
BLAKE2b-256 | 0f62bdf39ffbd15079d42c1d648190c04ab6883328cb77ec5fabe73e089cb4c3 |