Migrate from django-jsonform¶
This package places schema ownership on the Django form and leaves persistence
as a normal models.JSONField.
Model¶
Before:
from django_jsonform.models.fields import JSONField
class Product(models.Model):
configuration = JSONField(schema=configuration_schema, default=dict)
After:
from django.db import models
class Product(models.Model):
configuration = models.JSONField(default=dict)
Form¶
from django_native_jsonform import JSONSchemaFormField, JSONSchemaModelForm
class ProductForm(JSONSchemaModelForm):
configuration = JSONSchemaFormField(
schema=configuration_schema,
required=False,
)
class Meta:
model = Product
fields = "__all__"
Assign the form to ModelAdmin and add JSONSchemaAdminMixin when schemas or
custom factories use request context.
Historical migrations¶
Existing Django migrations may import field classes from the old dependency. Do not casually rewrite applied migrations. The application may need to retain that dependency until migrations are squashed, even when no runtime form uses it.
Changing the live model field class from a third-party JSONField to Django's
native JSONField often produces an AlterField state migration with no SQL
column change. Confirm with sqlmigrate in the consuming project.
Schema differences¶
- Move widget decisions into
widget, a registry, oroverrides. - Use
const/single-valueenumdiscriminators for predictableoneOfswitching. - Decide whether defaults should remain sparse (
preserve) or be stored (materialize). - Register application-specific formats such as file pickers; they are not assumed by the core package.
- Add
JSONSchemaFormMixinwhen retaining a custom existing Form base.
Rollout checklist¶
- Add the package to
INSTALLED_APPS. - Convert persistence fields to
models.JSONFieldwhere appropriate. - Declare
JSONSchemaFormFieldon each ModelForm. - Add context integration for admin/views.
- Register project-specific fields and widgets.
- Inspect schema defaults and unknown-key behavior.
- Generate and inspect migrations.
- Exercise add, edit, invalid submission, arrays, and every union branch.