Skip to main content

mizdb-inlines

Django inline formsets with bootstrap for the MIZDB app.

Requires django_bootstrap5.

Formsets will be rendered in a layout with two columns. One column is for the formset form, and the other column is for the delete button of a given formset form.

Installation

Install using pip:

pip install mizdb-inlines

Add to your INSTALLED_APPS in your settings.py:

INSTALLED_APPS = [
    ...,
    "mizdb_inlines",
]

Usage

Add mizdb_inlines/js/mizdb_inlines.js javascript and render the formset using the inline_formset template tag from the mizdb_inlines template tag library:

<!DOCTYPE html>
{% load static mizdb_inlines django_bootstrap5 %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My Awesome Form</title>
    {{ combined_media }}
    <script src="{% static 'mizdb_inlines/js/mizdb_inlines.js' %}"></script>
    {% bootstrap_css %}
    {% bootstrap_javascript %}
</head>
<body>
<form class="container mt-3" method="post">
    {% csrf_token %}

    {% bootstrap_form form %}
    {% inline_formset formset layout="horizontal" %}
    {% bootstrap_button button_type="submit" button_class="btn-success" content="Save" %}
    {% bootstrap_button button_type="reset" button_class="btn-warning" content="Reset" %}
</form>
</body>
</html>

The template tag instantiates an InlineFormsetRenderer and returns the renderers render() output. The template tag passes all keyword arguments along to the renderer. The renderer takes an additional keyword argument add_text with which you can set the text of the add button (defaults to the verbose name of the inline formset model). For example, in a template:

{% inline_formset formset layout="horizontal" add_text="Add another delicious Topping" %}

View mixin for inline formsets

Use the InlineFormsetMixin view mixin to remove some of the boilerplate from handling inline formsets. Simply declare the formset classes to use in the formset_classes attribute.

from mizdb_inlines.views import InlineFormsetMixin


class MyView(InlineFormsetMixin, UpdateView):
    model = Pizza
    fields = "__all__"
    template_name = "pizza.html"
    success_url = "/"

    formset_classes = (
        inlineformset_factory(Pizza, Toppings, fields="__all__", extra=1),
        MyAwesomeFormset,
    )

This will add formset instances to the template context with the context variable formsets. The combined media of the formsets and the view's model form is available with the variable combined_media :

{{ combined_media }}

{% for formset in formsets %}
    {% inline_formset formset %}
{% endfor %}

To perform additional actions after the form and formsets have been saved, you can use the post_save hook:

class MyView(InlineFormsetMixin, UpdateView):
    ...
    
    def post_save(self, form, formsets):
        # Log that the form was saved:
        create_logentry(form, formsets)

Tabular inline formset

If you prefer the formset fields to be in a tabular layout, you can use the tabular_inline_formset template tag instead:

{% load mizdb_inlines %}

{% for formset in formsets %}
    {% tabular_inline_formset formset %}
{% endfor %}

Development & Demo

python3 -m venv venv
source venv/bin/activate
make init

See the demo for a preview: run make init-demo and then start the demo server python demo/manage.py runserver.

Run tests with make test. To install required browsers for playwright: playwright install.

Metadata

Release files for mizdb-inlines 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 mizdb-inlines 0.3.1
File Size Uploaded
mizdb_inlines-0.3.1.tar.gz 13.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mizdb-inlines 0.3.1
File Interpreter ABI Platform
mizdb_inlines-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.1 kB

Release files / mizdb_inlines-0.3.1.tar.gz

Download URL mizdb_inlines-0.3.1.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fd38a8dc2b9b6399dec0245e18420ee352771f312783cda246c87af90def8177
BLAKE2b-256 checksum
How to use checksums
57bea76cb7476f58f710fc6113cbeac7056f9e05910215b70aab8d69ab0f28c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release files / mizdb_inlines-0.3.1-py3-none-any.whl

Download URL mizdb_inlines-0.3.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e77c648aaf1f95264f963d2d8464ec2c149b1e99ca8a9e3309ac4fd1450b9123
BLAKE2b-256 checksum
How to use checksums
e974e249d483fdb19a44e1e002c47e85c90efe19328c1259b1b725c19fef04eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

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