django-class-based-views 0

A work in progress. Hopefully not too broken. Needs documentation.

4 years after

Django class-based views

Work on ticket #6735.

Installation

$ python setup.py install

Or for the moment:

$ pip install -e [email protected]:bfirsh/django-class-based-views.git#egg=django-cbv

Usage

Inherit your own class-based views from existing ones listed below:

class AuthorDetail(class_based_views.DetailView):
    queryset = Author.objects.all()

You can also use the configure class method as a shortcut.

Declare your view in your URLs like you already do for classic views:

import views
from django.conf.urls.defaults import *

urlpatterns = patterns('',
    url(r'^detail/author/(?P<pk>\d+)/$',
        views.AuthorDetail.as_view,
        name="author_detail"),
)

Note: you must use the as_view method of the class in your URLs, not the class in order to avoid shared attributes across requests.

Views

CRUD views

  • ListView: Render some list of objects, set by self.queryset. This can be any iterable of items, not just a queryset.

  • DetailView: Render a "detail" view of an object. By default this is a model instance looked up from self.queryset, but the view will support display of any object by overriding self.get_object().

  • CreateView: View for creating an object.

  • UpdateView: View for updating an object.

  • DeleteView: View for deleting an object retrieved with self.get_object().

HTTP support: note that you can use POST or PUT HTTP verb for creating/editing an object and POST or DELETE for deleting an object.

Extra views

  • PaginatedListView
  • ProcessFormView
  • ProcessModelFormView
  • DisplayFormView
  • DisplayModelFormView

Date-based views

  • ArchiveView
  • YearView
  • MonthView
  • WeekView
  • DayView
  • TodayView
  • DateDetailView

API

TODO

Related Repositories

django-vanilla-views

django-vanilla-views

Beautifully simple class-based views. ...

django-chartjs

django-chartjs

Django Class Based Views to generate Ajax charts js parameters. ...

django-daydreamer

django-daydreamer

A Django class-based view utility library ...

flask-views

flask-views

Class-based views for Flask ...

django-cbv

django-cbv

Class Based Views backported from Django trunk ...


Top Contributors

bfirsh davidbgk spookylukey