Metadata-Version: 2.5
Name: django-native-jsonform
Version: 0.1.1
Summary: Build deeply customizable native Django forms from JSON Schema.
Project-URL: Documentation, https://barcelona-dev.github.io/django-native-jsonform/
Project-URL: Issues, https://github.com/Barcelona-DEV/django-native-jsonform/issues
Project-URL: Repository, https://github.com/Barcelona-DEV/django-native-jsonform
Author: andrico
License-Expression: MIT
License-File: LICENSE
Keywords: admin,django,forms,json,json-schema,jsonfield
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: django<7.0,>=4.2
Provides-Extra: dev
Requires-Dist: coverage[toml]>=7.6; extra == 'dev'
Requires-Dist: mkdocs-material>=9.5; extra == 'dev'
Requires-Dist: mkdocs>=1.6; extra == 'dev'
Requires-Dist: mkdocstrings[python]>=0.27; extra == 'dev'
Requires-Dist: pytest-django>=4.9; extra == 'dev'
Requires-Dist: pytest>=8.3; extra == 'dev'
Requires-Dist: ruff>=0.8; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocs>=1.6; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.27; extra == 'docs'
Provides-Extra: test
Requires-Dist: coverage[toml]>=7.6; extra == 'test'
Requires-Dist: pytest-django>=4.9; extra == 'test'
Requires-Dist: pytest>=8.3; extra == 'test'
Description-Content-Type: text/markdown

# django-native-jsonform

[![PyPI](https://img.shields.io/pypi/v/django-native-jsonform.svg)](https://pypi.org/project/django-native-jsonform/)
[![Python](https://img.shields.io/pypi/pyversions/django-native-jsonform.svg)](https://pypi.org/project/django-native-jsonform/)
[![Django](https://img.shields.io/badge/Django-4.2%20%7C%205.x-0C4B33)](https://www.djangoproject.com/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Build nested, server-validated JSON editors from JSON Schema using ordinary
Django `Field`, `Widget`, `Form`, and `ModelForm` primitives.

`django-native-jsonform` is intended for applications that store configurable
data in `models.JSONField` but still want Django's validation, permissions,
widgets, templates, admin integration, and extension points.

## Highlights

- Objects, arrays, nested arrays, choices, local `$ref`, and discriminated
  `oneOf` branches.
- Native Django fields and server-side validation—no client-only JSON editor.
- Dynamic schemas with access to the current request, user, object, and form.
- Exact-path, `*`, and `**` overrides for fields, widgets, attributes,
  serializers, defaults, permissions, and templates.
- Cloneable registries for project-specific JSON formats and widgets.
- Sparse JSON preservation: displayed defaults do not have to be persisted.
- Unknown-key preservation for forward-compatible and permission-aware forms.
- Template-driven rendering and small progressive-enhancement JavaScript.

## Installation

```bash
python -m pip install django-native-jsonform
```

```python
INSTALLED_APPS = [
    # ...
    "django_native_jsonform",
]
```

## Quick start

```python
from django import forms

from django_native_jsonform import JSONSchemaFormField, JSONSchemaModelForm

from .models import Product


PRODUCT_SCHEMA = {
    "type": "object",
    "properties": {
        "title": {"type": "string", "title": "Title"},
        "price": {"type": "number", "minimum": 0},
        "tags": {
            "type": "array",
            "items": {"type": "string"},
        },
    },
    "required": ["title"],
}


class ProductForm(JSONSchemaModelForm):
    metadata = JSONSchemaFormField(schema=PRODUCT_SCHEMA, required=False)

    class Meta:
        model = Product
        fields = "__all__"
```

For Django admin, add `JSONSchemaAdminMixin` so callable schemas and factories
receive the current request context:

```python
from django.contrib import admin
from django_native_jsonform import JSONSchemaAdminMixin


@admin.register(Product)
class ProductAdmin(JSONSchemaAdminMixin, admin.ModelAdmin):
    form = ProductForm
```

## Customize a project-specific format

```python
from django import forms
from django_native_jsonform import FieldFactoryContext, default_registry

registry = default_registry.clone()


@registry.register_field("string", format="media-asset")
def media_asset_field(context: FieldFactoryContext) -> forms.Field:
    return MediaAssetField(
        user=context.form_context.user,
        schema=context.schema,
        required=context.required,
    )


class ProductForm(JSONSchemaModelForm):
    metadata = JSONSchemaFormField(schema=PRODUCT_SCHEMA, registry=registry)
```

The package does not depend on a particular rich text editor, media library,
autocomplete implementation, or design system. Those are registered by each
consumer.

## Documentation

The complete wiki lives in [`docs/`](docs/index.md) and is published at
[barcelona-dev.github.io/django-native-jsonform](https://barcelona-dev.github.io/django-native-jsonform/).

Start with the [quick start](docs/quick-start.md), then see
[customization](docs/customization.md) and
[building extensions](docs/extensions.md).

## Status

The API is currently alpha. It was extracted from a production Django
application, but semantic-versioning compatibility begins with `1.0`.

## License

MIT
