Skip to main content

Django app for content-type–scoped dynamic templates with NamedID slugs

Project description

django-dynamic-template

Django app for content-type–scoped dynamic templates: store DTL fragments in the database, address them with a named_id slug (django-namedid), inject optional related querysets and a structured object dict into each fragment.

Requirements

  • Python ≥ 3.10
  • Django ≥ 3.2
  • django-namedid (declared in pyproject.toml; VCS pin until stable wheels are available)

Installation

From the repository root (editable install recommended for local work):

pip install -e .

Add the app and dependencies you need:

INSTALLED_APPS = [
    # ...
    "dynamic_template",
]

Optional: django-boosted (admin preview), django-richtextfield (TinyMCE-style widget) — see pyproject.toml [project.optional-dependencies] dev.

Concepts

Piece Role
DynamicTemplate label, content_type, named_id, template (richtext), plus model_fields, annotate_fields, fields shaping object in the fragment
DynamicRelationContext Related queryset (manager + filters), same three JSON fields per row; rows are tuples of dicts in the fragment
{% dyntpl %} Loads a template by named_id, merges context, evaluates relation contexts, then replaces object with a plain dict
  • model_fields: ORM column names (empty → all concrete fields on the model).
  • annotate_fields: list of annotation aliases already on the queryset / instance — this app does not call .annotate(); your manager or view must provide them.
  • fields: extra Python names resolved with getattr (@property, class attributes, methods).

Filters on relations: filter_spec (resolved from object + template context) and filter_literal (static ORM kwargs). See docs/purpose.md for full detail.

Template tag

{% load dyntpl %}

{% dyntpl "my-block-named-id" %}
{% dyntpl tpl_id obj=article %}
{% dyntpl tpl_id ctype=Product obj=product %}
  • obj=: must match the template’s content_type.
  • ctype=: disambiguates when the same named_id exists for several models.
  • Other keyword arguments are merged into the inner fragment context.

In the fragment, use {{ object.name }}, {% for row in article %}{{ row.title }}{% endfor %}, {{ rows|length }} (not .count on querysets).

Settings (optional)

# Import path to a widget class for the template field in admin
DYNAMIC_TEMPLATE_RICHTEXT_WIDGET = "djrichtextfield.widgets.RichTextWidget"

Development

pytest

pyproject.toml sets DJANGO_SETTINGS_MODULE=tests.settings and pythonpath=["src"].

Apply migrations for the bundled test project:

PYTHONPATH=src DJANGO_SETTINGS_MODULE=tests.settings python manage.py migrate

More detail: docs/ (purpose.md, structure.md, development.md).

License

MIT

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_dynamic_template-0.2.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

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

django_dynamic_template-0.2.0-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file django_dynamic_template-0.2.0.tar.gz.

File metadata

  • Download URL: django_dynamic_template-0.2.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_dynamic_template-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a81df4f9cc466f3db00c5bb15fdbc1c36502dc9648bfdc726606baadb3f6ffe9
MD5 99dcbc91fc121f93c6a334e7c1e02562
BLAKE2b-256 c6fd812fde2626f337f7555ef923d0540fa12f88cef8681ea6de4203989f4bb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_dynamic_template-0.2.0.tar.gz:

Publisher: release.yml on octolo/django-dynamic-template

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_dynamic_template-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dynamic_template-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fd2bde944403a9665774bf7396591c1fb4ad4f4bf63a38ba2236c9a7575ebca
MD5 21cfe0def1d13576b669e20f75d98e8f
BLAKE2b-256 38660600a0e8ff95d6a85ec9c49ff346cc2e4a584a91195f6705cfe389f4f18c

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_dynamic_template-0.2.0-py3-none-any.whl:

Publisher: release.yml on octolo/django-dynamic-template

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