Skip to main content

Expose JSONField data as a virtual django model fields.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-jsonfield-schema, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size django-jsonfield-schema-0.3.0.tar.gz (18.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page