Giter Site home page Giter Site logo

pmaino / django-extra-views Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andrewingram/django-extra-views

0.0 0.0 0.0 379 KB

Django's class-based generic views are awesome, let's have more of them.

License: MIT License

Python 96.11% HTML 3.89%

django-extra-views's Introduction

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.

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>

django-extra-views's People

Contributors

andrewingram avatar jonashaag avatar geyser avatar sdolemelipone avatar miguelrestrepo avatar mjumbewu avatar therefromhere avatar zeus avatar pidelport avatar ddaan avatar luzfcb avatar dmvass avatar freeworlder avatar jlucchese avatar voidus avatar sebcorbin avatar montiniz avatar jgsogo avatar wilabs-ab avatar sergei-maertens avatar xrmx avatar dekkers avatar aidanlister avatar jproffitt avatar henward0 avatar xavierdutreilh avatar bcanyelles avatar tomwys avatar rodrmartinez avatar pcgentry avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.