Skip to main content

Extra class-based views for Django

Project description

Django’s class-based generic views are great, they let you accomplish a large number of web application design patterns in relatively few lines of code. They do have their limits though, and that’s what this library of views aims to overcome.

Installation

Installing from pypi (using pip).

pip install django-extra-views

Installing from github.

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

Features so far

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

  • InlineFormSetView - Lets you edit formsets related to a model (uses inlineformset_factory)

  • CreateWithInlinesView and UpdateWithInlinesView - Lets you edit a model and its relations

  • GenericInlineFormSetView, the equivalent of InlineFormSetView but for GenericForeignKeys

  • Support for generic inlines in CreateWithInlinesView and UpdateWithInlinesView

Still to do

I’d like to 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.

Examples

Defining a FormSetView.

from extra_views import FormSetView

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

Defining a ModelFormSetView.

from extra_views import ModelFormSetView:

class ItemFormSetView(ModelFormSetView):
    model = Item
    template_name = 'item_formset.html'

Defining a CreateWithInlinesView and an UpdateWithInlinesView.

from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet
from extra_views.generic import GenericInlineFormSet

class ItemInline(InlineFormSet):
    model = Item

class TagInline(GenericInlineFormSet):
    model = Tag

class CreateOrderView(CreateWithInlinesView):
    model = Order
    inlines = [ItemInline, TagInline]

class UpdateOrderView(UpdateWithInlinesView):
    model = Order
    inlines = [ItemInline, TagInline]

# Example URLs.
urlpatterns = patterns('',
    url(r'^orders/new/$', CreateOrderView.as_view()),
    url(r'^orders/(?P<pk>\d+)/$', UpdateOrderView.as_view()),
)

More descriptive examples to come.

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-extra-views-0.2.2.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file django-extra-views-0.2.2.tar.gz.

File metadata

File hashes

Hashes for django-extra-views-0.2.2.tar.gz
Algorithm Hash digest
SHA256 9f83c51304c42a522c0054d44091b978fb5f6c75d1edf9ba7f4efc4761b61fcd
MD5 b66080af0722c6ef9ba31dea0d18b796
BLAKE2b-256 b74b1a3913e64cfc6b39620b0a242fbfb23791a2fbcfe37f3f75a2c3fe638781

See more details on using hashes here.

Supported by

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