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 ≥ 0.1.0 (installed automatically via
pyproject.toml)
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 withgetattr(@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’scontent_type.ctype=: disambiguates when the samenamed_idexists 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_dynamic_template-0.1.0.tar.gz.
File metadata
- Download URL: django_dynamic_template-0.1.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcc45ec9a59fc27b3eb553ac557a1db4c6005369fcf9adddbbe8d127aaeaf518
|
|
| MD5 |
d761e30b4a512a71f56f9f9daa7a2ac7
|
|
| BLAKE2b-256 |
e7db54a1e212b5fe2cfa2e57eb995a94445107474cc35e3506e1925c826e7a22
|
File details
Details for the file django_dynamic_template-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_dynamic_template-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e260843ebb44d3e7cc163b87dd5b3ecaeabc15b2a268a5bac36d334e0c99217
|
|
| MD5 |
ffa6e905dfe83fecd72ed89238b4d7e9
|
|
| BLAKE2b-256 |
2e82fccb380f11fca841065b3dccd5d6ed2cc0b28cb0f2f5ea3fc34ccd9fc0cf
|