Loading docs/ref/class-based-views/generic-date-based.txt +12 −12 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ ArchiveIndexView month or day using the attribute ``date_list_period``. This also applies to all subclass views. **Example views.py**:: **Example myapp/views.py**:: from django.conf.urls import patterns, url from django.views.generic.dates import ArchiveIndexView Loading Loading @@ -160,7 +160,7 @@ YearArchiveView * Uses a default ``template_name_suffix`` of ``_archive_year``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import YearArchiveView Loading @@ -172,7 +172,7 @@ YearArchiveView make_object_list = True allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -255,7 +255,7 @@ MonthArchiveView * Uses a default ``template_name_suffix`` of ``_archive_month``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import MonthArchiveView Loading @@ -267,7 +267,7 @@ MonthArchiveView make_object_list = True allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -348,7 +348,7 @@ WeekArchiveView * Uses a default ``template_name_suffix`` of ``_archive_week``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import WeekArchiveView Loading @@ -361,7 +361,7 @@ WeekArchiveView week_format = "%W" allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -463,7 +463,7 @@ DayArchiveView * Uses a default ``template_name_suffix`` of ``_archive_day``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import DayArchiveView Loading @@ -475,7 +475,7 @@ DayArchiveView make_object_list = True allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -537,7 +537,7 @@ TodayArchiveView * Uses a default ``template_name_suffix`` of ``_archive_today``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import TodayArchiveView Loading @@ -549,7 +549,7 @@ TodayArchiveView make_object_list = True allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -599,7 +599,7 @@ DateDetailView * Uses a default ``template_name_suffix`` of ``_detail``. **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url from django.views.generic.dates import DateDetailView Loading docs/ref/class-based-views/generic-display.txt +26 −3 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ DetailView 9. ``get()`` 10. :meth:`~django.views.generic.base.TemplateResponseMixin.render_to_response()` **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.detail import DetailView from django.utils import timezone Loading @@ -52,7 +52,7 @@ DetailView context['now'] = timezone.now() return context **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading @@ -62,6 +62,16 @@ DetailView url(r'^(?P<slug>[-_\w]+)/$', ArticleDetailView.as_view(), name='article-detail'), ) **Example myapp/article_detail.html**: .. code-block:: html+django <h1>{{ object.headline }}</h1> <p>{{ object.content }}</p> <p>Reporter: {{ object.reporter }}</p> <p>Published: {{ object.pub_date|date }}</p> <p>Date: {{ object.now|date }}</p> ListView -------- Loading Loading @@ -111,7 +121,7 @@ ListView context['now'] = timezone.now() return context **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading @@ -121,6 +131,19 @@ ListView url(r'^$', ArticleListView.as_view(), name='article-list'), ) **Example myapp/article_list.html**: .. code-block:: html+django <h1>Articles</h1> <ul> {% for article in object_list %} <li>{{ article.pub_date|date }} - {{ article.headline }}</li> {% empty %} <li>No articles yet.</li> {% endfor %} </ul> .. class:: django.views.generic.list.BaseListView A base view for displaying a list of objects. It is not intended to be used Loading docs/ref/class-based-views/generic-editing.txt +43 −6 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ FormView * :class:`django.views.generic.edit.ProcessFormView` * :class:`django.views.generic.base.View` **Example forms.py**:: **Example myapp/forms.py**:: from django import forms Loading @@ -54,7 +54,7 @@ FormView # send email using the self.cleaned_data dictionary pass **Example views.py**:: **Example myapp/views.py**:: from myapp.forms import ContactForm from django.views.generic.edit import FormView Loading @@ -70,6 +70,16 @@ FormView form.send_email() return super(ContactView, self).form_valid(form) **Example myapp/contact.html**: .. code-block:: html+django <form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Send message" /> </form> CreateView ---------- Loading Loading @@ -101,7 +111,7 @@ CreateView creating objects for the example ``Author`` model would cause the default ``template_name`` to be ``'myapp/author_create_form.html'``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.edit import CreateView from myapp.models import Author Loading @@ -110,6 +120,15 @@ CreateView model = Author fields = ['name'] **Example myapp/author_form.html**: .. code-block:: html+django <form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Create" /> </form> UpdateView ---------- Loading Loading @@ -143,7 +162,7 @@ UpdateView updating objects for the example ``Author`` model would cause the default ``template_name`` to be ``'myapp/author_update_form.html'``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.edit import UpdateView from myapp.models import Author Loading @@ -151,6 +170,16 @@ UpdateView class AuthorUpdate(UpdateView): model = Author fields = ['name'] template_name_suffix = '_update_form' **Example myapp/author_update_form.html**: .. code-block:: html+django <form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Update" /> </form> DeleteView ---------- Loading Loading @@ -184,8 +213,7 @@ DeleteView deleting objects for the example ``Author`` model would cause the default ``template_name`` to be ``'myapp/author_check_delete.html'``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.edit import DeleteView from django.core.urlresolvers import reverse_lazy Loading @@ -194,3 +222,12 @@ DeleteView class AuthorDelete(DeleteView): model = Author success_url = reverse_lazy('author-list') **Example myapp/author_confirm_delete.html**: .. code-block:: html+django <form action="" method="post">{% csrf_token %} <p>Are you sure you want to delete "{{ object }}"?</p> <input type="submit" value="Confirm" /> </form> Loading
docs/ref/class-based-views/generic-date-based.txt +12 −12 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ ArchiveIndexView month or day using the attribute ``date_list_period``. This also applies to all subclass views. **Example views.py**:: **Example myapp/views.py**:: from django.conf.urls import patterns, url from django.views.generic.dates import ArchiveIndexView Loading Loading @@ -160,7 +160,7 @@ YearArchiveView * Uses a default ``template_name_suffix`` of ``_archive_year``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import YearArchiveView Loading @@ -172,7 +172,7 @@ YearArchiveView make_object_list = True allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -255,7 +255,7 @@ MonthArchiveView * Uses a default ``template_name_suffix`` of ``_archive_month``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import MonthArchiveView Loading @@ -267,7 +267,7 @@ MonthArchiveView make_object_list = True allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -348,7 +348,7 @@ WeekArchiveView * Uses a default ``template_name_suffix`` of ``_archive_week``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import WeekArchiveView Loading @@ -361,7 +361,7 @@ WeekArchiveView week_format = "%W" allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -463,7 +463,7 @@ DayArchiveView * Uses a default ``template_name_suffix`` of ``_archive_day``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import DayArchiveView Loading @@ -475,7 +475,7 @@ DayArchiveView make_object_list = True allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -537,7 +537,7 @@ TodayArchiveView * Uses a default ``template_name_suffix`` of ``_archive_today``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.dates import TodayArchiveView Loading @@ -549,7 +549,7 @@ TodayArchiveView make_object_list = True allow_future = True **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading Loading @@ -599,7 +599,7 @@ DateDetailView * Uses a default ``template_name_suffix`` of ``_detail``. **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url from django.views.generic.dates import DateDetailView Loading
docs/ref/class-based-views/generic-display.txt +26 −3 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ DetailView 9. ``get()`` 10. :meth:`~django.views.generic.base.TemplateResponseMixin.render_to_response()` **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.detail import DetailView from django.utils import timezone Loading @@ -52,7 +52,7 @@ DetailView context['now'] = timezone.now() return context **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading @@ -62,6 +62,16 @@ DetailView url(r'^(?P<slug>[-_\w]+)/$', ArticleDetailView.as_view(), name='article-detail'), ) **Example myapp/article_detail.html**: .. code-block:: html+django <h1>{{ object.headline }}</h1> <p>{{ object.content }}</p> <p>Reporter: {{ object.reporter }}</p> <p>Published: {{ object.pub_date|date }}</p> <p>Date: {{ object.now|date }}</p> ListView -------- Loading Loading @@ -111,7 +121,7 @@ ListView context['now'] = timezone.now() return context **Example urls.py**:: **Example myapp/urls.py**:: from django.conf.urls import patterns, url Loading @@ -121,6 +131,19 @@ ListView url(r'^$', ArticleListView.as_view(), name='article-list'), ) **Example myapp/article_list.html**: .. code-block:: html+django <h1>Articles</h1> <ul> {% for article in object_list %} <li>{{ article.pub_date|date }} - {{ article.headline }}</li> {% empty %} <li>No articles yet.</li> {% endfor %} </ul> .. class:: django.views.generic.list.BaseListView A base view for displaying a list of objects. It is not intended to be used Loading
docs/ref/class-based-views/generic-editing.txt +43 −6 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ FormView * :class:`django.views.generic.edit.ProcessFormView` * :class:`django.views.generic.base.View` **Example forms.py**:: **Example myapp/forms.py**:: from django import forms Loading @@ -54,7 +54,7 @@ FormView # send email using the self.cleaned_data dictionary pass **Example views.py**:: **Example myapp/views.py**:: from myapp.forms import ContactForm from django.views.generic.edit import FormView Loading @@ -70,6 +70,16 @@ FormView form.send_email() return super(ContactView, self).form_valid(form) **Example myapp/contact.html**: .. code-block:: html+django <form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Send message" /> </form> CreateView ---------- Loading Loading @@ -101,7 +111,7 @@ CreateView creating objects for the example ``Author`` model would cause the default ``template_name`` to be ``'myapp/author_create_form.html'``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.edit import CreateView from myapp.models import Author Loading @@ -110,6 +120,15 @@ CreateView model = Author fields = ['name'] **Example myapp/author_form.html**: .. code-block:: html+django <form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Create" /> </form> UpdateView ---------- Loading Loading @@ -143,7 +162,7 @@ UpdateView updating objects for the example ``Author`` model would cause the default ``template_name`` to be ``'myapp/author_update_form.html'``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.edit import UpdateView from myapp.models import Author Loading @@ -151,6 +170,16 @@ UpdateView class AuthorUpdate(UpdateView): model = Author fields = ['name'] template_name_suffix = '_update_form' **Example myapp/author_update_form.html**: .. code-block:: html+django <form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Update" /> </form> DeleteView ---------- Loading Loading @@ -184,8 +213,7 @@ DeleteView deleting objects for the example ``Author`` model would cause the default ``template_name`` to be ``'myapp/author_check_delete.html'``. **Example views.py**:: **Example myapp/views.py**:: from django.views.generic.edit import DeleteView from django.core.urlresolvers import reverse_lazy Loading @@ -194,3 +222,12 @@ DeleteView class AuthorDelete(DeleteView): model = Author success_url = reverse_lazy('author-list') **Example myapp/author_confirm_delete.html**: .. code-block:: html+django <form action="" method="post">{% csrf_token %} <p>Are you sure you want to delete "{{ object }}"?</p> <input type="submit" value="Confirm" /> </form>