django-eav-json-fields
Schema-validated JSONFields for Django using an EAV-style DSL.
Define expected keys, types, and constraints on JSON dict values stored in Django JSONFields. Storage remains plain JSONB in PostgreSQL -- the EAV layer adds validation, type coercion, and admin widgets.
Requirements
- Python 3.10+
- Django 4.2+
Installation
pip install django-eav-json-fields
No INSTALLED_APPS entry is needed.
Quick Start
Define a schema
from eav_fields import EAVSchema, EAVBoolean, EAVString, EAVDecimal, EAVInteger
class ServiceConfig(EAVSchema):
enabled = EAVBoolean(default=True, help_text="Enable this service")
label = EAVString(max_length=100, help_text="Display name")
price = EAVDecimal(required=False, max_digits=10, decimal_places=2)
max_retries = EAVInteger(min_value=0, max_value=10, default=3, required=False)
Use EAVField on a model
from django.db import models
from eav_fields import EAVField
class Service(models.Model):
name = models.CharField(max_length=100)
config = EAVField(schema=ServiceConfig)
The field validates during full_clean() that the JSON dict conforms to the schema. Unknown keys are rejected, types are coerced, and constraints are enforced.
Polymorphic schemas
Select a schema based on another field's value:
class Product(models.Model):
product_type = models.CharField(max_length=20, choices=[("a", "Type A"), ("b", "Type B")])
config = EAVField(
schema_map={"a": SchemaA, "b": SchemaB},
schema_key_field="product_type",
)
EAV Attribute Types
| Type | Python Type | JSON Storage | Constraints |
|---|---|---|---|
EAVString |
str |
string | max_length, choices |
EAVBoolean |
bool |
boolean | -- |
EAVInteger |
int |
number | min_value, max_value, choices |
EAVFloat |
float |
number | min_value, max_value, choices |
EAVDecimal |
Decimal |
string | max_digits, decimal_places, min_value, max_value, choices |
All attributes support: required (default True), default, help_text, choices.
Cross-field Validation
Override validate_cross for rules spanning multiple attributes:
from django.core.exceptions import ValidationError
from eav_fields import EAVSchema, EAVInteger
class MyConfig(EAVSchema):
min_val = EAVInteger()
max_val = EAVInteger()
@classmethod
def validate_cross(cls, data):
if data.get("min_val", 0) >= data.get("max_val", 0):
raise ValidationError({"max_val": ["max_val must be greater than min_val."]})
Schema Inheritance
Child schemas inherit parent attributes and can override them:
class BaseConfig(EAVSchema):
name = EAVString()
class ExtendedConfig(BaseConfig):
count = EAVInteger() # inherits 'name' from parent
Admin Widget
EAVField automatically provides an EAVWidget in the Django admin that renders typed HTML inputs for each schema attribute, with show/hide support for polymorphic schemas.
Migration Support
Schema references are serialized as dotted import paths in migrations. Both class references and string paths are accepted:
# Both are equivalent:
config = EAVField(schema=MySchema)
config = EAVField(schema="myapp.schemas.MySchema")
License
MIT
Metadata
Release files for django-eav-json-fields 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_eav_json_fields-0.1.0.tar.gz | 9.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_eav_json_fields-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.6 kB
Release files / django_eav_json_fields-0.1.0.tar.gz
| Download URL | django_eav_json_fields-0.1.0.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74a60dab87805fd5e87bb98808f2b9c4f47042e87c860d1d624b0a69a8dc2afb
|
|
BLAKE2b-256 checksum How to use checksums |
1a4cbce1088b1f834774e286b87af86064db1a1a187620cdeb318cbcf7ba738e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 21, 2026.
Transparency logRelease files / django_eav_json_fields-0.1.0-py3-none-any.whl
| Download URL | django_eav_json_fields-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f3a6381c66b40a5480e449e774b5cdb8246fe82445bb3437fcc26afecbaacf1
|
|
BLAKE2b-256 checksum How to use checksums |
387badabcdcbe87ac632c29a3381718835602c04416fb682a693620a1ffa24bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 21, 2026.
Transparency log