Skip to main content

User-defined typed JSON objects for Django, powered by django-structured-json-field

Project description

Test PyPI License: MIT

django-structured-metaobjects

User-defined, typed JSON objects for Django — built on top of django-structured-json-field.

Editors define meta types in the admin (a list of typed field definitions). Each MetaInstance then picks one of those types and the admin form / REST API automatically adapts to the schema declared by the chosen type.

Features

  • Field kinds: string, html, number, boolean, date, datetime, select, ref (single FK), queryset (list of FKs), group (nested object), list (repeating group), with optional translated=True per-field.
  • Runtime Pydantic compiler with per-MetaType caching, invalidated on save.
  • Admin form rebuilds the data widget for the selected meta type.
  • DRF MetaTypeViewSet / MetaInstanceViewSet with schema/ action.
  • Typed access on instance.obj.<field> returning the parsed Pydantic model — FK / queryset fields lazily resolve to real Django objects with structured-json-field's caching.

Install

pip install django-structured-metaobjects

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    "structured",
    "structured_metaobjects",
]

Wire the REST endpoints into your router:

from rest_framework import routers
from structured_metaobjects.views import MetaTypeViewSet, MetaInstanceViewSet

router = routers.DefaultRouter()
router.register(r"meta-types", MetaTypeViewSet, "meta-types")
router.register(r"meta-instances", MetaInstanceViewSet, "meta-instances")

Field kinds

kind Python type built by the compiler Notes
string str Supports multiline, min_length, max_length, placeholder.
html str Rich-text. Supports placeholder.
number float / int Set integer=True for int. Supports minimum, maximum.
boolean bool
date datetime.date
datetime datetime.datetime
select str Requires choices (list of {value, label}).
ref <TargetModel> Requires target_model="app.Model".
queryset List[<TargetModel>] Requires target_model="app.Model".
group nested Pydantic model from children Requires children.
list List[<group model>] from children Requires children.

Setting translated=True wraps the field in Dict[str, T] so the value is a per-language map.

Typed access

instance = MetaInstance.objects.get(pk=1)
obj = instance.obj                # cached Pydantic instance
obj.title                         # typed string
obj.related_page                  # real Django model instance (lazy/cached)
obj.gallery                       # list of real Django model instances

Project details


Download files

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

Source Distribution

django_structured_metaobjects-1.1.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_structured_metaobjects-1.1.0-py2.py3-none-any.whl (29.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django_structured_metaobjects-1.1.0.tar.gz.

File metadata

File hashes

Hashes for django_structured_metaobjects-1.1.0.tar.gz
Algorithm Hash digest
SHA256 bad5a51190133c0be9e2dcb231be028ad3c6831008b5ec81c76088b97cff6583
MD5 ffdbdb5d66afbc97ffd02ffe4d2c3638
BLAKE2b-256 032a664a454148e93d3674672a001c35202a4cdab72ea37374eeadf2048fb8ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_structured_metaobjects-1.1.0.tar.gz:

Publisher: cd.yml on bnznamco/django-structured-metaobjects

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_structured_metaobjects-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_structured_metaobjects-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9bf8f83045a036132ddcfd6ad52112c9cc1e1059f0218c200478a452ef174232
MD5 1f2421c645c661c51f63211a2de9c75d
BLAKE2b-256 dd780bb1703a1020af47f15185e985adf08897dfe70448679b5b1ccd28d38fc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_structured_metaobjects-1.1.0-py2.py3-none-any.whl:

Publisher: cd.yml on bnznamco/django-structured-metaobjects

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page