JSON Storage

viewflow.jsonstore.* is the set of virtual Django Model fields stores it’s data inside single JSON database column.

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

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

Quick start

from viewflow import jsonstore
from django import forms
from django.contrib import admin
from django.db import models

class Employee(models.Model):
    data = JSONField(default={})
    full_name = jsonstore.CharField(max_length=250)
    hire_date = jsonstore.DateField()
    salary = jsonstore.DecimalField(max_digits=10, decimal_places=2)

The result model works like usual django model. All virtual fields are available to construct ModelForms, Viewsets and Admin interfaces.

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')]

Polymorphic models

JSON Store plays well with proxy models. Additional virtual fields allows to model different real-life objects, without involving multi-table inheritance.

from django.contrib.auth.models import AbstractUser
from viewflow import jsonstore

class User(PolymorphicModel, AbstractUser):
    data = jsonstore.JSONField(null=True, default={})

class Client(User):
    address = jsonstore.CharField(max_length=250)
    zip_code = jsonstore.CharField(max_length=250)
    city = jsonstore.CharField(max_length=250)
    vip = jsonstore.BooleanField()

    class Meta:
        proxy = True

API

class
viewflow.jsonstore.BooleanField
class
viewflow.jsonstore.CharField
class
viewflow.jsonstore.DateField
class
viewflow.jsonstore.DateTimeField
class
viewflow.jsonstore.DecimalField
class
viewflow.jsonstore.EmailField
class
viewflow.jsonstore.FloatField
class
viewflow.jsonstore.IntegerField
class
viewflow.jsonstore.IPAddressField
class
viewflow.jsonstore.GenericIPAddressField
class
viewflow.jsonstore.NullBooleanField
class
viewflow.jsonstore.TextField
class
viewflow.jsonstore.TimeField
class
viewflow.jsonstore.URLField