Skip to main content

Django Formsets with ECMAScript 6.

Project description

django-easy-formset

Django Formsets with ECMAScript 6

Python tests Upload Python Package

Installation

Installation is easy using pip and the only requirement is a recent version of Django.

python -m pip install django-easy-formset

Basic app configuration

Then to add the Django Easy Formset to your project add the app easy_formset to your INSTALLED_APPS.

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

How to use

Video

Video

In template

{% load static %}
<head>
  <link rel="stylesheet" href="{% static 'easy_formset/easy_formset.css' %}">
</head>
<body>
  <div id="{{ formset.prefix }}">
    {{ formset.management_form }}

    <template formset-empty-form="{{ formset.prefix }}">
      {{ formset.empty_form.as_p }}
      <a formset-form-delete>Delete</a>
    </template>

    <div formset-forms="{{ formset.prefix }}">
      {% for form in formset.forms %}
        <div formset-form>
          {{ form.as_p }}
          <a formset-form-delete>Delete</a>
        </div>
      {% endfor %}
    </div>
    <button formset-add="{{ formset.prefix }}">Add Formset</button>
  </div>
  ...
  <script src="{% static 'easy_formset/easy_formset.js' %}"></script>
  <script>
    const formset = new Formset("{{ formset.prefix }}")
  </script>
</body>

Custom undo element

// add one root element...
Formset.revertHTML = '<a href="#">Custom undo link...</a>'

const formset = new Formset("{{ formset.prefix }}")

Handle add/deleted events

document.addEventListener('formset:add', (event) => {
  // access the form with event.detail.form
})

document.addEventListener('formset:deleted', (event) => {
  // access the form with event.detail.form
})

Nested formsets

See examples in tests.testapp.

Run tests

python -m pip -r requirements.txt
pytest

Run project test

python manage.py runserver

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-easy-formset-0.2.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

django_easy_formset-0.2.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file django-easy-formset-0.2.2.tar.gz.

File metadata

  • Download URL: django-easy-formset-0.2.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for django-easy-formset-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7bbe1474b0b188fdcdfbfac0cca3696de88beab191bea3c133a1ae5692950e3e
MD5 76112c54dc0dc1e8c78cf1816d098883
BLAKE2b-256 3dd156cf359d3cc1f1d3849769d3c07a907f26810cf7b41915771f5e750fb762

See more details on using hashes here.

File details

Details for the file django_easy_formset-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: django_easy_formset-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for django_easy_formset-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 888bbc22d035ab7961d34bb8c023ac0c093b3f4168a3f94b95c14a56cfebac6f
MD5 736abb8841de0f20a6751dfd31a518c8
BLAKE2b-256 89ed0b3249d46a93ab3c9540fe9895288ce33edb5f4cf8a9837c1a6d40d658ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page