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: primitives, 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
text str Multi-line.
integer int
number float
boolean bool
date datetime.date
datetime datetime.datetime
ref <TargetModel> Requires target_model="app.Model".
queryset List[<TargetModel>] Requires target_model="app.Model".
group nested Pydantic model from children
list List[<group model>] from 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.0.0.tar.gz (18.8 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.0.0-py2.py3-none-any.whl (27.1 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for django_structured_metaobjects-1.0.0.tar.gz
Algorithm Hash digest
SHA256 01c5dfd38345610a52d71bac61b8a6a6d37919443c50f15e62c9e68b36dd982e
MD5 c6d314c04e696aff542127606ff38fd9
BLAKE2b-256 191fd5e4f1e27f3333461821ac60f2bda10aa509290b20247cb9641d0c376cb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_structured_metaobjects-1.0.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.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_structured_metaobjects-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 47961d945953039adfd4f94993e489fc9546e87d1824c01a5b136ed1c7baf17e
MD5 32de442cdf6fc32201f75368a69fbc99
BLAKE2b-256 6dae013c106568f934c16d80ba29a4aff78bf1e89b1ab419c8e4ba0d0e262476

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_structured_metaobjects-1.0.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