Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
Last active Aug 29, 2015
Embed
What would you like to do?
django-forms-builder add-on for paragraph support

form-builder-addons

Add-ons for django-forms-builder.

List of add-ons

  • NoneField (allows to use paragraphs in the django-forms-builder).

Installation

Make the following changes in the settings module of your Django project.

  1. Install django-nonefield.
pip install django-nonefield
  1. Add form_builder_addons, to the INSTALLED_APPS:
INSTALLED_APPS = (
    # ...
    'form_builder_addons',
    # ...
)
  1. Add the following line somewhere:
# Additional django-forms-builder conf
FORMS_BUILDER_EXTRA_FIELDS = (
    (20, 'nonefield.fields.NoneField', gettext("Paragraph")),
)

FORMS_BUILDER_EXTRA_WIDGETS = (
    (20, 'nonefield.fields.NoneWidget'),
)
# END Additional django-forms-builder conf
  1. Add the following line in the "field.html" template of your crispy forms.
{% load form_builder_addons_crispy_form_fields %}

...

{% elif field|is_nonefield %}
    <p>{{ field.value }}</p>

...

Full example.

{% load crispy_forms_field form_builder_addons_crispy_form_fields %}

{% if field.is_hidden %}
    {{ field }}
{% elif field|is_nonefield %}
    <p>{{ field.value }}</p>
{% else %}
    ... The rest
# File "form_builder_addons/templatetags/form_builder_addons_crispy_form_fields.py"
from django import template
from nonefield.widgets import NoneWidget
register = template.Library()
@register.filter
def is_nonefield(field):
"""
Check if it's a NoneField.
"""
return isinstance(field.field.widget, NoneWidget)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment