Permalink
Browse files

Added mention in MRO section about method/attribute inheritence. Adde…

…d simple examples to Generic editing views, added index to Generic editing views and Editing mixins, added missing template_name_suffix attribute to Generic editing views.
  • Loading branch information...
pydanny committed Jul 16, 2012
1 parent 35ddeee commit dea554bd9df193ee11b7d924ffa0631fabdfdaee
Showing with 112 additions and 4 deletions.
  1. +102 −4 docs/ref/class-based-views/generic-editing.txt
  2. +10 −0 docs/ref/class-based-views/mixins-editing.txt
@@ -2,7 +2,26 @@
Generic editing views
=====================
-The views described here provide a foundation for editing content.
+The following views are described on this page and provide a foundation for
+editing content:
+
+* :class:`django.views.generic.edit.FormView`
+* :class:`django.views.generic.edit.CreateView`
+* :class:`django.views.generic.edit.UpdateView`
+* :class:`django.views.generic.edit.DeleteView`
+
+.. note:: Some of the examples on this page assume that a model titled 'authors'
+ has been defined. For these cases we assume the following has been defined
+ in `myapps.models.py`::
+
+ from django import models
+ from django.core.urlresolvers import reverse
+
+ class Author(models.Model):
+ name = models.CharField(max_length=200)
+
+ def get_absolute_url(self):
+ return reverse('author-detail', kwargs={'pk': self.pk})
.. class:: django.views.generic.edit.FormView
@@ -11,20 +30,53 @@ The views described here provide a foundation for editing content.
**Ancestors (MRO)**
+ This view inherits methods and attributes from the following views:
+
* :class:`django.views.generic.edit.FormView`
* :class:`django.views.generic.base.TemplateResponseMixin`
* :class:`django.views.generic.edit.BaseFormView`
* :class:`django.views.generic.edit.FormMixin`
* :class:`django.views.generic.edit.ProcessFormView`
* :class:`django.views.generic.base.View`
+ **Example forms.py**::
+
+ from django import forms
+
+ class ContactForm(forms.Form):
+ name = forms.CharField()
+ message = forms.CharField(widget=forms.Textarea)
+
+ def send_email(self):
+ # send email using the self.cleaned_data dictionary
+ pass
+
+ **Example views.py**::
+
+ from myapp.forms import ContactForm
+ from django.views.generic.edit import FormView
+
+ class ContactView(FormView):
+ template_name = 'contact.html'
+ form_class = ContactForm
+ success_url = '/thanks/'
+
+ def form_valid(self, form):
+ # This method is called when valid form data has been POSTed.
+ # It should return an HttpResponse.
+ form.send_email()
+ return super(ContactView, self).form_valid(form)
+
+
.. class:: django.views.generic.edit.CreateView
A view that displays a form for creating an object, redisplaying the form
with validation errors (if there are any) and saving the object.
**Ancestors (MRO)**
+ This view inherits methods and attributes from the following views:
+
* :class:`django.views.generic.edit.CreateView`
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
* :class:`django.views.generic.base.TemplateResponseMixin`
@@ -35,6 +87,21 @@ The views described here provide a foundation for editing content.
* :class:`django.views.generic.edit.ProcessFormView`
* :class:`django.views.generic.base.View`
+ **Attributes**
+
+ .. attribute:: template_name_suffix
+
+ The CreateView page displayed to a GET request uses a
+ ``template_name_suffix`` of ``'_form'``.
+
+ **Example views.py**::
+
+ from django.views.generic.edit import CreateView
+ from myapp.models import Author
+
+ class AuthorCreate(CreateView):
+ model = Author
+
.. class:: django.views.generic.edit.UpdateView
A view that displays a form for editing an existing object, redisplaying
@@ -44,6 +111,8 @@ The views described here provide a foundation for editing content.
**Ancestors (MRO)**
+ This view inherits methods and attributes from the following views:
+
* :class:`django.views.generic.edit.UpdateView`
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
* :class:`django.views.generic.base.TemplateResponseMixin`
@@ -54,6 +123,21 @@ The views described here provide a foundation for editing content.
* :class:`django.views.generic.edit.ProcessFormView`
* :class:`django.views.generic.base.View`
+ **Attributes**
+
+ .. attribute:: template_name_suffix
+
+ The CreateView page displayed to a GET request uses a
+ ``template_name_suffix`` of ``'_form'``.
+
+ **Example views.py**::
+
+ from django.views.generic.edit import UpdateView
+ from myapp.models import Author
+
+ class AuthorUpdate(UpdateView):
+ model = Author
+
.. class:: django.views.generic.edit.DeleteView
A view that displays a confirmation page and deletes an existing object.
@@ -63,6 +147,8 @@ The views described here provide a foundation for editing content.
**Ancestors (MRO)**
+ This view inherits methods and attributes from the following views:
+
* :class:`django.views.generic.edit.DeleteView`
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
* :class:`django.views.generic.base.TemplateResponseMixin`
@@ -72,7 +158,19 @@ The views described here provide a foundation for editing content.
* :class:`django.views.generic.detail.SingleObjectMixin`
* :class:`django.views.generic.base.View`
- **Notes**
+ **Attributes**
+
+ .. attribute:: template_name_suffix
+
+ The CreateView page displayed to a GET request uses a
+ ``template_name_suffix`` of ``'_confirm_delete'``.
+
+ **Example views.py**::
+
+ from django.views.generic.edit import DeleteView
+ from django.core.urlresolvers import reverse_lazy
+ from myapp.models import Author
- * The delete confirmation page displayed to a GET request uses a
- ``template_name_suffix`` of ``'_confirm_delete'``.
+ class AuthorDelete(DeleteView):
+ model = Author
+ success_url = reverse_lazy('author-list')
@@ -2,6 +2,16 @@
Editing mixins
==============
+The following mixins are used to construct Django's editing views:
+
+* :class:`django.views.generic.edit.FormMixin`
+* :class:`django.views.generic.edit.ModelFormMixin`
+* :class:`django.views.generic.edit.ProcessFormView`
+* :class:`django.views.generic.edit.DeletionMixin`
+
+.. note:: Examples of how these are combined into editing views can be found at
+ the documentation on ``Generic editing views``.
+
.. class:: django.views.generic.edit.FormMixin
A mixin class that provides facilities for creating and displaying forms.

0 comments on commit dea554b

Please sign in to comment.