Added mention in MRO section about method/attribute inheritence. Added 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.
This commit is contained in:
parent
35ddeee455
commit
dea554bd9d
|
@ -2,7 +2,26 @@
|
||||||
Generic editing views
|
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
|
.. class:: django.views.generic.edit.FormView
|
||||||
|
|
||||||
|
@ -11,6 +30,8 @@ The views described here provide a foundation for editing content.
|
||||||
|
|
||||||
**Ancestors (MRO)**
|
**Ancestors (MRO)**
|
||||||
|
|
||||||
|
This view inherits methods and attributes from the following views:
|
||||||
|
|
||||||
* :class:`django.views.generic.edit.FormView`
|
* :class:`django.views.generic.edit.FormView`
|
||||||
* :class:`django.views.generic.base.TemplateResponseMixin`
|
* :class:`django.views.generic.base.TemplateResponseMixin`
|
||||||
* :class:`django.views.generic.edit.BaseFormView`
|
* :class:`django.views.generic.edit.BaseFormView`
|
||||||
|
@ -18,6 +39,35 @@ The views described here provide a foundation for editing content.
|
||||||
* :class:`django.views.generic.edit.ProcessFormView`
|
* :class:`django.views.generic.edit.ProcessFormView`
|
||||||
* :class:`django.views.generic.base.View`
|
* :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
|
.. class:: django.views.generic.edit.CreateView
|
||||||
|
|
||||||
A view that displays a form for creating an object, redisplaying the form
|
A view that displays a form for creating an object, redisplaying the form
|
||||||
|
@ -25,6 +75,8 @@ The views described here provide a foundation for editing content.
|
||||||
|
|
||||||
**Ancestors (MRO)**
|
**Ancestors (MRO)**
|
||||||
|
|
||||||
|
This view inherits methods and attributes from the following views:
|
||||||
|
|
||||||
* :class:`django.views.generic.edit.CreateView`
|
* :class:`django.views.generic.edit.CreateView`
|
||||||
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
|
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
|
||||||
* :class:`django.views.generic.base.TemplateResponseMixin`
|
* :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.edit.ProcessFormView`
|
||||||
* :class:`django.views.generic.base.View`
|
* :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
|
.. class:: django.views.generic.edit.UpdateView
|
||||||
|
|
||||||
A view that displays a form for editing an existing object, redisplaying
|
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)**
|
**Ancestors (MRO)**
|
||||||
|
|
||||||
|
This view inherits methods and attributes from the following views:
|
||||||
|
|
||||||
* :class:`django.views.generic.edit.UpdateView`
|
* :class:`django.views.generic.edit.UpdateView`
|
||||||
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
|
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
|
||||||
* :class:`django.views.generic.base.TemplateResponseMixin`
|
* :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.edit.ProcessFormView`
|
||||||
* :class:`django.views.generic.base.View`
|
* :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
|
.. class:: django.views.generic.edit.DeleteView
|
||||||
|
|
||||||
A view that displays a confirmation page and deletes an existing object.
|
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)**
|
**Ancestors (MRO)**
|
||||||
|
|
||||||
|
This view inherits methods and attributes from the following views:
|
||||||
|
|
||||||
* :class:`django.views.generic.edit.DeleteView`
|
* :class:`django.views.generic.edit.DeleteView`
|
||||||
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
|
* :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
|
||||||
* :class:`django.views.generic.base.TemplateResponseMixin`
|
* :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.detail.SingleObjectMixin`
|
||||||
* :class:`django.views.generic.base.View`
|
* :class:`django.views.generic.base.View`
|
||||||
|
|
||||||
**Notes**
|
**Attributes**
|
||||||
|
|
||||||
* The delete confirmation page displayed to a GET request uses a
|
.. attribute:: template_name_suffix
|
||||||
``template_name_suffix`` of ``'_confirm_delete'``.
|
|
||||||
|
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
|
||||||
|
|
||||||
|
class AuthorDelete(DeleteView):
|
||||||
|
model = Author
|
||||||
|
success_url = reverse_lazy('author-list')
|
||||||
|
|
|
@ -2,6 +2,16 @@
|
||||||
Editing mixins
|
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
|
.. class:: django.views.generic.edit.FormMixin
|
||||||
|
|
||||||
A mixin class that provides facilities for creating and displaying forms.
|
A mixin class that provides facilities for creating and displaying forms.
|
||||||
|
|
Loading…
Reference in New Issue