Skip to main content

Django JSONField-Schema

Expose Django JSONField data as virtual model fields

Use ModelForm and ModelAdmin as usual. Perform simple queries. Migrate to real table columns when needed without code change.

Suitable to store dumb business data, quick prototypes without DB migrations, and replace multi-table inheritance joins.

https://img.shields.io/pypi/v/django-jsonfield-schema.svg https://img.shields.io/pypi/pyversions/django-jsonfield-schema.svg https://img.shields.io/pypi/djversions/django-jsonfield-schema.svg

Use with caution! Replacing relational structures with JSON data should be mindfull architecture decision.

Works with any JSONField django.contrib.postgres, django-annoying, django-mysql, upcoming django Cross-db JSONField

Work in progress part of https://json-schema.org definitions are only supported.

Quick start

from django import forms
from django.contrib import admin
from django.db import models
from jsonfield_schema import JSONSchema

class EmployeeSchema(JSONSchema):
    full_name = {
        "type": "string"
    }

    hire_date = {
        "type": "string",
        "format": "date"
    }

    salary = {
        "type": "number",
        "multiplyOf": 0.01,
    }

class Employee(models.Model):
    _schema = EmployeeSchema()
    data = JSONField(default={})

class EmployeeForm(forms.ModelForm):
    class Meta:
        model = Employee
        fields = ['full_name', 'hire_date', 'salary']

@admin.register(Employee)
class EmployeeAdmin(admin.ModelAdmin):
    list_display = ['full_name', 'hire_date']
    fields = ['full_name', ('hire_date', 'salary')]

Demo

The demo shows how to handle multiple User types within single table with JSONField and Django-Polymodels proxies.

$ export DATABASE_URL=postgresql://viewflow:viewflow@localhost/viewflow
$ export DJANGO_SETTINGS_MODULE=demo.settings
$ tox python manage.py migrate
$ tox python manage.py runserver

License

Django JSONField-Schema is an Open Source project licensed under the terms of the AGPL license - The GNU Affero General Public License v3.0 with the Additional Permissions described in LICENSE_EXCEPTION

You can more read about AGPL at AGPL FAQ This package license scheme follows to GCC Runtime library licensing. If you use Linux already, probably this package license, should not bring anything new to your stack.

Latest changelog

0.3.0 2019-11-01

  • Support for date/time/datetime values

  • Support for help_text (description) and verbose_name (verboseName) field specs

Metadata

Release files for django-jsonfield-schema 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-jsonfield-schema 0.3.0
File Size Uploaded Provenance Actions
django-jsonfield-schema-0.3.0.tar.gz 18.7 kB Without provenance Details for django-jsonfield-schema-0.3.0.tar.gz

Release files / django-jsonfield-schema-0.3.0.tar.gz

Download URL django-jsonfield-schema-0.3.0.tar.gz
Size 18.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0cd5c220ac57771a4036dc8c1126d7cc8a502e7ae68c49b40c6482e51c3dc2a5
BLAKE2b-256 checksum
How to use checksums
8989d97d9f78c6c74a7138f599edd55977d44c96a8e0c09b84030d6b8cb0efa7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.10.0 pkginfo/1.2.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.8

Security for django-jsonfield-schema 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page