|
@@ -2,7 +2,7 @@
|
|
|
Generic editing views
|
|
|
=====================
|
|
|
|
|
|
-The following views are described on this page and provide a foundation for
|
|
|
+The following views are described on this page and provide a foundation for
|
|
|
editing content:
|
|
|
|
|
|
* :class:`django.views.generic.edit.FormView`
|
|
@@ -13,7 +13,7 @@ editing content:
|
|
|
.. note::
|
|
|
|
|
|
Some of the examples on this page assume that a model titled 'Author'
|
|
|
- has been defined. For these cases we assume the following has been defined
|
|
|
+ has been defined. For these cases we assume the following has been defined
|
|
|
in `myapp/models.py`::
|
|
|
|
|
|
from django import models
|
|
@@ -25,6 +25,9 @@ editing content:
|
|
|
def get_absolute_url(self):
|
|
|
return reverse('author-detail', kwargs={'pk': self.pk})
|
|
|
|
|
|
+FormView
|
|
|
+--------
|
|
|
+
|
|
|
.. class:: django.views.generic.edit.FormView
|
|
|
|
|
|
A view that displays a form. On error, redisplays the form with validation
|
|
@@ -69,6 +72,8 @@ editing content:
|
|
|
form.send_email()
|
|
|
return super(ContactView, self).form_valid(form)
|
|
|
|
|
|
+CreateView
|
|
|
+----------
|
|
|
|
|
|
.. class:: django.views.generic.edit.CreateView
|
|
|
|
|
@@ -94,7 +99,7 @@ editing content:
|
|
|
.. attribute:: template_name_suffix
|
|
|
|
|
|
The CreateView page displayed to a GET request uses a
|
|
|
- ``template_name_suffix`` of ``'_form.html'``. For
|
|
|
+ ``template_name_suffix`` of ``'_form.html'``. For
|
|
|
example, changing this attribute to ``'_create_form.html'`` for a view
|
|
|
creating objects for the the example `Author` model would cause the the
|
|
|
default `template_name` to be ``'myapp/author_create_form.html'``.
|
|
@@ -107,6 +112,9 @@ editing content:
|
|
|
class AuthorCreate(CreateView):
|
|
|
model = Author
|
|
|
|
|
|
+UpdateView
|
|
|
+----------
|
|
|
+
|
|
|
.. class:: django.views.generic.edit.UpdateView
|
|
|
|
|
|
A view that displays a form for editing an existing object, redisplaying
|
|
@@ -133,10 +141,10 @@ editing content:
|
|
|
.. attribute:: template_name_suffix
|
|
|
|
|
|
The UpdateView page displayed to a GET request uses a
|
|
|
- ``template_name_suffix`` of ``'_form.html'``. For
|
|
|
+ ``template_name_suffix`` of ``'_form.html'``. For
|
|
|
example, changing this attribute to ``'_update_form.html'`` for a view
|
|
|
updating objects for the the example `Author` model would cause the the
|
|
|
- default `template_name` to be ``'myapp/author_update_form.html'``.
|
|
|
+ default `template_name` to be ``'myapp/author_update_form.html'``.
|
|
|
|
|
|
**Example views.py**::
|
|
|
|
|
@@ -146,6 +154,9 @@ editing content:
|
|
|
class AuthorUpdate(UpdateView):
|
|
|
model = Author
|
|
|
|
|
|
+DeleteView
|
|
|
+----------
|
|
|
+
|
|
|
.. class:: django.views.generic.edit.DeleteView
|
|
|
|
|
|
A view that displays a confirmation page and deletes an existing object.
|
|
@@ -171,10 +182,10 @@ editing content:
|
|
|
.. attribute:: template_name_suffix
|
|
|
|
|
|
The DeleteView page displayed to a GET request uses a
|
|
|
- ``template_name_suffix`` of ``'_confirm_delete.html'``. For
|
|
|
+ ``template_name_suffix`` of ``'_confirm_delete.html'``. For
|
|
|
example, changing this attribute to ``'_check_delete.html'`` for a view
|
|
|
deleting objects for the the example `Author` model would cause the the
|
|
|
- default `template_name` to be ``'myapp/author_check_delete.html'``.
|
|
|
+ default `template_name` to be ``'myapp/author_check_delete.html'``.
|
|
|
|
|
|
|
|
|
**Example views.py**::
|
|
@@ -185,4 +196,4 @@ editing content:
|
|
|
|
|
|
class AuthorDelete(DeleteView):
|
|
|
model = Author
|
|
|
- success_url = reverse_lazy('author-list')
|
|
|
+ success_url = reverse_lazy('author-list')
|