Skip to main content
https://badge.fury.io/py/django-template-field.png https://travis-ci.org/orcasgit/django-template-field.png?branch=master

A Django template field with a manager to return the rendered template.

Documentation

The full documentation is at https://django-template-field.readthedocs.org.

Quickstart

Install django-template-field:

pip install django-template-field

Then use it in a project:

from django.db import models

from templatefield import fields, managers


class TemplatedText(models.Model):
    value = fields.TemplateTextField()

    # Manager that returns rendered templates. This will be the default
    # manager since it is first. Now, when accessed via `Related Models`_
    # this field will also be rendered.
    objects_rendered = managers.RenderTemplateManager()
    # Django's default manager returns unrendered templates.
    objects_unrendered = models.Manager()

Extra context can be added in settings like so:

TEMPLATE_FIELD_CONTEXT = { ‘template_var’: value }

Context can also be added to querysets like so:

TemplatedText.objects_rendered.with_context({‘template_var2’: value2})

If you dump fixtures with RenderTemplateManager as the default manager, django will render the exported data. To work around that, create an alternate settings file for your project with the following setting:

TEMPLATE_FIELD_RENDER = False

Then you can dump your unrendered data like so:

./manage.py dumpdata myapp.mymodel –settings=myapp.dump_settings

Admin

Using RenderTemplateManager as the default has the unfortunate side effect of rendering your fields in the Django admin, so we have provided a class from which you can inherit to solve that problem. Ex:

from templatefield import admin

class TemplatedTextAdmin(admin.UnrenderedAdmin):

…

Running Tests

source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install -r requirements/test.txt (myenv) $ python runtests.py

History

0.3.1 (2016-01-11)

  • Add setting to disable rendering

0.3.0 (2016-01-06)

  • Enable rendering in related field access

0.2.0 (2015-10-23)

  • Add with_context to RenderTemplateManager

0.1.0 (2015-10-02)

  • First release on PyPI.

Metadata

Release files for django-template-field 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-template-field 0.3.1
File Size Uploaded
django-template-field-0.3.1.tar.gz 7.6 kB Details

Release files / django-template-field-0.3.1.tar.gz

Download URL django-template-field-0.3.1.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3fe7a6507641de5595d952bb13c85bd8237ae5fa825bfb3e6442668202414581
BLAKE2b-256 checksum
How to use checksums
262b4679c26e87d67f01d74f581ae06734b69443f952a8254242082eee80a5a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.1 This release

1 release file

0.3.0

1 release file

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page