Skip to main content

Build Status Coverage Status Documentation Status

Django Extra Views - The missing class-based generic views for Django

Django-extra-views is a Django package which introduces additional class-based views in order to simplify common design patterns such as those found in the Django admin interface.

Supported Python and Django versions: Python 3.6+, Django 2.2-5.1, see tox.ini for an up-to-date list.

Full documentation is available at read the docs.

Installation

Install the stable release from pypi (using pip):

pip install django-extra-views

Or install the current master branch from github:

pip install -e git://github.com/AndrewIngram/django-extra-views.git#egg=django-extra-views

Then add 'extra_views' to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'extra_views',
    ...
]

Features

  • FormSet and ModelFormSet views - The formset equivalents of FormView and ModelFormView.

  • InlineFormSetView - Lets you edit a formset related to a model (using Django’s inlineformset_factory).

  • CreateWithInlinesView and UpdateWithInlinesView - Lets you edit a model and multiple inline formsets all in one view.

  • GenericInlineFormSetView, the equivalent of InlineFormSetView but for GenericForeignKeys.

  • Support for generic inlines in CreateWithInlinesView and UpdateWithInlinesView.

  • Support for naming each inline or formset in the template context with NamedFormsetsMixin.

  • SortableListMixin - Generic mixin for sorting functionality in your views.

  • SearchableListMixin - Generic mixin for search functionality in your views.

  • SuccessMessageMixin and FormSetSuccessMessageMixin - Generic mixins to display success messages after form submission.

Still to do

Add support for pagination in ModelFormSetView and its derivatives, the goal being to be able to mimic the change_list view in Django’s admin. Currently this is proving difficult because of how Django’s MultipleObjectMixin handles pagination.

Quick Examples

FormSetView

Define a FormSetView, a view which creates a single formset from django.forms.formset_factory and adds it to the context.

from extra_views import FormSetView
from my_forms import AddressForm

class AddressFormSet(FormSetView):
    form_class = AddressForm
    template_name = 'address_formset.html'

Then within address_formset.html, render the formset like this:

<form method="post">
  ...
  {{ formset }}
  ...
  <input type="submit" value="Submit" />
</form>

ModelFormSetView

Define a ModelFormSetView, a view which works as FormSetView but instead renders a model formset using django.forms.modelformset_factory.

from extra_views import ModelFormSetView


class ItemFormSetView(ModelFormSetView):
    model = Item
    fields = ['name', 'sku']
    template_name = 'item_formset.html'

CreateWithInlinesView or UpdateWithInlinesView

Define CreateWithInlinesView and UpdateWithInlinesView, views which render a form to create/update a model instance and its related inline formsets. Each of the InlineFormSetFactory classes use similar class definitions as the ModelFormSetView.

from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSetFactory


class ItemInline(InlineFormSetFactory):
    model = Item
    fields = ['sku', 'price', 'name']


class ContactInline(InlineFormSetFactory):
    model = Contact
    fields = ['name', 'email']


class CreateOrderView(CreateWithInlinesView):
    model = Order
    inlines = [ItemInline, ContactInline]
    fields = ['customer', 'name']
    template_name = 'order_and_items.html'


class UpdateOrderView(UpdateWithInlinesView):
    model = Order
    inlines = [ItemInline, ContactInline]
    fields = ['customer', 'name']
    template_name = 'order_and_items.html'

Then within order_and_items.html, render the formset like this:

<form method="post">
  ...
  {{ form }}

  {% for formset in inlines %}
    {{ formset }}
  {% endfor %}
  ...
  <input type="submit" value="Submit" />
</form>

Contributing

Pull requests are welcome. To run all tests locally, setup a virtual environment and run

tox

Before committing, use pre-commit to check all formatting and linting

pip install pre-commit
pre-commmit install

This will automatically run black, isort and flake8 before the commit is accepted.

Release files for django-extra-views 0.16.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-extra-views 0.16.0
File Size Uploaded
django_extra_views-0.16.0.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-extra-views 0.16.0
File Interpreter ABI Platform
django_extra_views-0.16.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.6 kB

Release files / django_extra_views-0.16.0.tar.gz

Download URL django_extra_views-0.16.0.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7f8e07bd6c9388816a7c08d752661172d4078758c2079fc0cadddfcf5cd38ae3
BLAKE2b-256 checksum
How to use checksums
ac61c6d2ced11fc4235d2aeb422ad5af3b516effd942e2be5a263a5d93dcb1e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / django_extra_views-0.16.0-py2.py3-none-any.whl

Download URL django_extra_views-0.16.0-py2.py3-none-any.whl
Size 15.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
af990d1779813b728231e94bcc703614fef60015c4c31d53185c5f4f898a37be
BLAKE2b-256 checksum
How to use checksums
106a511cf7ad5ac8d0890eb7ec374668759e9fbb263af98abb516fdc14be2633
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.16.0 This release

2 release files

0.15.0

1 release file

0.14.0

1 release file

0.13.0

1 release file

0.12.0

1 release file

0.11.0

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.0

1 release file

0.7.1

2 release files

0.7.0

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

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