a MarkupField for Django
This repository has moved to Codeberg, GitHub will remain as a read-only mirror.
.. image:: https://codeberg.org/jpt/django-markupfield/workflows/Test/badge.svg
.. image:: https://img.shields.io/pypi/v/django-markupfield.svg :target: https://pypi.python.org/pypi/django-markupfield
An implementation of a custom MarkupField for Django. A MarkupField is in essence a TextField with an associated markup type. The field also caches its rendered value on the assumption that disk space is cheaper than CPU cycles in a web application.
The recommended way to install django-markupfield is with
pip _
It is not necessary to add 'markupfield' to your INSTALLED_APPS, it
merely needs to be on your PYTHONPATH. However, to use titled markup you
either add 'markupfield' to your INSTALLED_APPS or add the
corresponding translations to your project translation.
Requires Django >= 2.2 and 3.6+
a.body.raw u'fancy' a.body.markup_type u'markdown' a.body.rendered u' fancy ' print unicode(a.body)
fancy
Assignment to a.body is equivalent to assignment to a.body.raw and
assignment to a.body_markup_type is equivalent to assignment to
a.body.markup_type.
.. important::
Keeping in mind that body is MarkupField instance is particullary important with default or default_if_none filter for model that could be blank. If body's rendered is None or empty string ("") these filters will not evaluate body as falsy to display default text::
{{ a.body|default:"" }}
That's because ``body`` is regular non-``None`` MarkupField instance. To let ``default`` or ``default_if_none`` filters to work evaluate ``rendered`` MarkupField attribute instead. To prevent escaping HTML for the case ``rendered`` is truethy, finish chain with ``safe`` filter::
{{ a.body.rendered|default:""|safe }} .. note:: a.body.rendered is only updated when a.save() is called
No open issues yet, or sync has not completed.