Django inline formsets with bootstrap
Project description
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>
{{ form.media }}
{{ formset.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="success" content="Save" %}
{% bootstrap_button button_type="reset" button_class="warning" content="Reset" %}
</form>
</body>
</html>
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 under the name formsets
:
{% for formset in formsets %}
{% 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
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mizdb-inlines-0.1.0.tar.gz
.
File metadata
- Download URL: mizdb-inlines-0.1.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cce9faf54bf5de95eab7bbef2595c55c088d59621cf23fc6296bed1c803a9e1d |
|
MD5 | b0eaa2b87be969390bfb9b587db199e2 |
|
BLAKE2b-256 | c323f700d27af4880e1b29e12729d03b5bcb0001f8bf7fa2c8f09789cc72cd42 |
File details
Details for the file mizdb_inlines-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: mizdb_inlines-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 514bf6eb422ea5713bb80b1babac8fb2797c1bc933068b1fc2f948576b7b3a6b |
|
MD5 | 33199911fa33f212552b9a62dc409a20 |
|
BLAKE2b-256 | d7542dff3e7a82f0df2b31039fa7ca29966bdae2a9413b32cad0dcc5bde84169 |