Django's excellent
Generic Views provide developers with most of what they need to get a site up and running (if they aren't using the Admin of course). The flexibility of these views is such that for most sites you don't need much else.
Extending these views is also well documented and probably covers off 95% of the situations where the plain generic views fall short.
In a recent project I found another area where the generic views fall short:
inline formsets.
I have added the ability to use inline formsets in generic views. The new view functions are drop in replacements for Django's with the addition of a new
inlines argument.
InstallationFrom SourceDownload
wadofstuff-django-views.
To install it, run the following command inside the unpacked source directory:
python setup.py install
From pypiIf you have the Python
easy_install utility available, you can
also type the following to download and install in one step:
easy_install wadofstuff-django-views
Or if you're using
pip:
pip install wadofstuff-django-views
Or if you'd prefer you can simply place the included
wadofstuffdirectory somewhere on your Python path, or symlink to it from
somewhere on your Python path; this is useful if you're working from a
Subversion checkout.
Note that this application requires Python 2.4 or later. You can obtain
Python from http://www.python.org/.
Usagewadofstuff.django.views.create_object(..., inlines=None)wadofstuff.django.views.update_object(..., inlines=None)These functions are identical to the Django ones except for the addition of the
inlines argument. This argument consists of a list of dictionaries that will
be passed as arguments after the
parent_model argument to
inlineformset_factory(parent_model, ...).
For example, arguments to a generic view might typically look like:
crud_dict = {
'model':Author
'inlines':[{
'model':Book,
'extra':2,
'form':BookForm,
},{
'model':Article,
}],
# ... other generic view arguments
}
would translate to calls to
inlineformset_factory() like:
inlineformset_factory(Author, model=Book, extra=2, form=BookForm)
and
inlineformset_factory(Author, model=Article)
The view function will create a formset for each inline model and add them to the template context. In the example above the context variables would be named
book_formset and
article_formset.
Update: A quick change to allow the views to be imported from
wadofstuff.django.views. Bumped version to 1.0.1.