{"id":16417261,"url":"https://github.com/matthiask/django-json-schema-editor","last_synced_at":"2025-04-09T17:25:34.494Z","repository":{"id":211462337,"uuid":"729161290","full_name":"matthiask/django-json-schema-editor","owner":"matthiask","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-24T19:20:10.000Z","size":350,"stargazers_count":38,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-06T06:34:23.119Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matthiask.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-08T15:03:41.000Z","updated_at":"2025-03-24T19:20:13.000Z","dependencies_parsed_at":"2024-10-26T21:18:15.024Z","dependency_job_id":"a69d477e-398b-4db8-8175-9b2bcbcf3f40","html_url":"https://github.com/matthiask/django-json-schema-editor","commit_stats":{"total_commits":116,"total_committers":2,"mean_commits":58.0,"dds":"0.12068965517241381","last_synced_commit":"58242ea09bbb2f93652b47b2bcb2a7f16f456b94"},"previous_names":["matthiask/django-jsoneditorwidget","matthiask/django-json-schema-editor"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthiask%2Fdjango-json-schema-editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthiask%2Fdjango-json-schema-editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthiask%2Fdjango-json-schema-editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthiask%2Fdjango-json-schema-editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matthiask","download_url":"https://codeload.github.com/matthiask/django-json-schema-editor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248075927,"owners_count":21043668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T07:11:23.724Z","updated_at":"2025-04-09T17:25:34.476Z","avatar_url":"https://github.com/matthiask.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Django JSON Schema Editor\n\nA powerful Django widget for integrating [`@json-editor/json-editor`](https://www.npmjs.com/package/@json-editor/json-editor) with Django forms and admin interfaces. It provides a rich, schema-based editing experience for JSON data in Django applications.\n\nSee [the blog post for the announcement and a screenshot](https://406.ch/writing/django-json-schema-editor/).\n\n## Features\n\n- Schema-based validation for JSON data\n- Django admin integration\n- Rich text editing capabilities with optional prose editor\n- Foreign key references with Django admin lookups\n- Referential integrity for JSON data containing model references\n\n## Installation\n\n```bash\npip install django-json-schema-editor\n```\n\nFor django-prose-editor support (rich text editing):\n\n```bash\npip install django-json-schema-editor[prose]\n```\n\n## Usage\n\n### Basic Setup\n\n1. Add `django_json_schema_editor` to your `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = [\n    # ...\n    'django_json_schema_editor',\n    # ...\n]\n```\n\n2. Use the `JSONField` in your models:\n\n```python\nfrom django.db import models\nfrom django_json_schema_editor.fields import JSONField\n\nclass MyModel(models.Model):\n    data = JSONField(\n        schema={\n            \"type\": \"object\",\n            \"properties\": {\n                \"title\": {\"type\": \"string\"},\n                \"description\": {\"type\": \"string\"},\n                \"count\": {\"type\": \"integer\"},\n            },\n        }\n    )\n```\n\n### Rich Text Editing\n\nFor rich text editing, use the `prose` format:\n\n```python\nclass MyModel(models.Model):\n    data = JSONField(\n        schema={\n            \"type\": \"object\",\n            \"properties\": {\n                \"title\": {\"type\": \"string\"},\n                \"content\": {\"type\": \"string\", \"format\": \"prose\"},\n            },\n        }\n    )\n```\n\n### Foreign Key References\n\nYou can reference Django models in your JSON data:\n\n```python\nclass MyModel(models.Model):\n    data = JSONField(\n        schema={\n            \"type\": \"object\",\n            \"properties\": {\n                \"title\": {\"type\": \"string\"},\n                \"image\": {\n                    \"type\": \"string\",\n                    \"format\": \"foreign_key\",\n                    \"options\": {\n                        \"url\": \"/admin/myapp/image/?_popup=1\u0026_to_field=id\",\n                    },\n                },\n            },\n        }\n    )\n```\n\n### Data References and Referential Integrity\n\nOne of the most powerful features is the ability to maintain referential integrity between JSON data and model instances:\n\n```python\nfrom django.db import models\nfrom django_json_schema_editor.fields import JSONField\n\nclass Image(models.Model):\n    title = models.CharField(max_length=100)\n    file = models.FileField(upload_to='images/')\n\nclass Article(models.Model):\n    data = JSONField(\n        schema={\n            \"type\": \"object\",\n            \"properties\": {\n                \"title\": {\"type\": \"string\"},\n                \"content\": {\"type\": \"string\", \"format\": \"prose\"},\n                \"featured_image\": {\n                    \"type\": \"string\",\n                    \"format\": \"foreign_key\",\n                    \"options\": {\n                        \"url\": \"/admin/myapp/image/?_popup=1\u0026_to_field=id\",\n                    },\n                },\n            },\n        }\n    )\n\ndef get_image_ids(article):\n    if image_id := article.data.get(\"featured_image\"):\n        return [int(image_id)]\n    return []\n\n# Register the reference to prevent images from being deleted when they're referenced\nArticle.register_data_reference(\n    Image,\n    name=\"featured_images\",\n    getter=get_image_ids,\n)\n```\n\nThis prevents a referenced image from being deleted as long as it's referenced in an article's JSON data.\n\nThe `name` field will be the name of the underlying `ManyToManyField` which actually references the `Image` instances.\n\n## JSON Schema Support\n\nThe widget supports the [JSON Schema](https://json-schema.org/) standard for defining the structure and validation rules of your JSON data. Notable supported features include:\n\n- Basic types: string, number, integer, boolean, array, object\n- Format validations: date, time, email, etc.\n- Custom formats: prose (rich text), foreign_key (model references)\n- Required properties\n- Enums and default values\n- Nested objects and arrays\n\nThe [documentation for the json-editor](https://www.npmjs.com/package/@json-editor/json-editor) offers a good overview over all supported features.\n\n## Development\n\nTo set up the development environment:\n\n1. Clone the repository\n2. Install development dependencies:\n\n```bash\npip install -e \".[tests,prose]\"\n```\n\n### Code Quality\n\nThis project uses several tools to maintain code quality:\n\n- **pre-commit**: We use pre-commit hooks to ensure consistent code style and quality\n- **ruff**: For Python linting and formatting\n- **biome**: For JavaScript and CSS linting and formatting\n\nTo set up pre-commit:\n\n```bash\nuv tool install pre-commit\npre-commit install\n```\n\nThe pre-commit configuration includes:\n- Basic file checks (trailing whitespace, merge conflicts, etc.)\n- Django upgrade checks\n- Ruff for Python linting and formatting\n- Biome for JavaScript and CSS linting and formatting\n- pyproject.toml validations\n\n### Running Tests\n\n```bash\npytest\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthiask%2Fdjango-json-schema-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthiask%2Fdjango-json-schema-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthiask%2Fdjango-json-schema-editor/lists"}