Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit dea554bd9df193ee11b7d924ffa0631fabdfdaee 1 parent 35ddeee
Daniel Greenfeld authored July 15, 2012
106  docs/ref/class-based-views/generic-editing.txt
@@ -2,7 +2,26 @@
2 2
 Generic editing views
3 3
 =====================
4 4
 
5  
-The views described here provide a foundation for editing content.
  5
+The following views are described on this page and provide a foundation for 
  6
+editing content:
  7
+
  8
+* :class:`django.views.generic.edit.FormView`
  9
+* :class:`django.views.generic.edit.CreateView`
  10
+* :class:`django.views.generic.edit.UpdateView`
  11
+* :class:`django.views.generic.edit.DeleteView`
  12
+
  13
+.. note:: Some of the examples on this page assume that a model titled 'authors'
  14
+    has been defined. For these cases we assume the following has been defined 
  15
+    in `myapps.models.py`::
  16
+
  17
+        from django import models
  18
+        from django.core.urlresolvers import reverse
  19
+
  20
+        class Author(models.Model):
  21
+            name = models.CharField(max_length=200)
  22
+
  23
+            def get_absolute_url(self):
  24
+                return reverse('author-detail', kwargs={'pk': self.pk})
6 25
 
7 26
 .. class:: django.views.generic.edit.FormView
8 27
 
@@ -11,6 +30,8 @@ The views described here provide a foundation for editing content.
11 30
 
12 31
     **Ancestors (MRO)**
13 32
 
  33
+    This view inherits methods and attributes from the following views:
  34
+
14 35
     * :class:`django.views.generic.edit.FormView`
15 36
     * :class:`django.views.generic.base.TemplateResponseMixin`
16 37
     * :class:`django.views.generic.edit.BaseFormView`
@@ -18,6 +39,35 @@ The views described here provide a foundation for editing content.
18 39
     * :class:`django.views.generic.edit.ProcessFormView`
19 40
     * :class:`django.views.generic.base.View`
20 41
 
  42
+    **Example forms.py**::
  43
+
  44
+        from django import forms
  45
+
  46
+        class ContactForm(forms.Form):
  47
+            name = forms.CharField()
  48
+            message = forms.CharField(widget=forms.Textarea)
  49
+
  50
+            def send_email(self):
  51
+                # send email using the self.cleaned_data dictionary
  52
+                pass
  53
+
  54
+    **Example views.py**::
  55
+
  56
+        from myapp.forms import ContactForm
  57
+        from django.views.generic.edit import FormView
  58
+
  59
+        class ContactView(FormView):
  60
+            template_name = 'contact.html'
  61
+            form_class = ContactForm
  62
+            success_url = '/thanks/'
  63
+
  64
+            def form_valid(self, form):
  65
+                # This method is called when valid form data has been POSTed.
  66
+                # It should return an HttpResponse.
  67
+                form.send_email()
  68
+                return super(ContactView, self).form_valid(form)
  69
+
  70
+
21 71
 .. class:: django.views.generic.edit.CreateView
22 72
 
23 73
     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.
25 75
 
26 76
     **Ancestors (MRO)**
27 77
 
  78
+    This view inherits methods and attributes from the following views:
  79
+
28 80
     * :class:`django.views.generic.edit.CreateView`
29 81
     * :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
30 82
     * :class:`django.views.generic.base.TemplateResponseMixin`
@@ -35,6 +87,21 @@ The views described here provide a foundation for editing content.
35 87
     * :class:`django.views.generic.edit.ProcessFormView`
36 88
     * :class:`django.views.generic.base.View`
37 89
 
  90
+    **Attributes**
  91
+
  92
+    .. attribute:: template_name_suffix
  93
+
  94
+        The CreateView page displayed to a GET request uses a
  95
+        ``template_name_suffix`` of ``'_form'``.
  96
+
  97
+    **Example views.py**::
  98
+
  99
+        from django.views.generic.edit import CreateView
  100
+        from myapp.models import Author
  101
+
  102
+        class AuthorCreate(CreateView):
  103
+            model = Author
  104
+
38 105
 .. class:: django.views.generic.edit.UpdateView
39 106
 
40 107
     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.
44 111
 
45 112
     **Ancestors (MRO)**
46 113
 
  114
+    This view inherits methods and attributes from the following views:
  115
+
47 116
     * :class:`django.views.generic.edit.UpdateView`
48 117
     * :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
49 118
     * :class:`django.views.generic.base.TemplateResponseMixin`
@@ -54,6 +123,21 @@ The views described here provide a foundation for editing content.
54 123
     * :class:`django.views.generic.edit.ProcessFormView`
55 124
     * :class:`django.views.generic.base.View`
56 125
 
  126
+    **Attributes**
  127
+
  128
+    .. attribute:: template_name_suffix
  129
+
  130
+        The CreateView page displayed to a GET request uses a
  131
+        ``template_name_suffix`` of ``'_form'``.
  132
+
  133
+    **Example views.py**::
  134
+
  135
+        from django.views.generic.edit import UpdateView
  136
+        from myapp.models import Author
  137
+
  138
+        class AuthorUpdate(UpdateView):
  139
+            model = Author
  140
+
57 141
 .. class:: django.views.generic.edit.DeleteView
58 142
 
59 143
     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.
63 147
 
64 148
     **Ancestors (MRO)**
65 149
 
  150
+    This view inherits methods and attributes from the following views:
  151
+
66 152
     * :class:`django.views.generic.edit.DeleteView`
67 153
     * :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
68 154
     * :class:`django.views.generic.base.TemplateResponseMixin`
@@ -72,7 +158,19 @@ The views described here provide a foundation for editing content.
72 158
     * :class:`django.views.generic.detail.SingleObjectMixin`
73 159
     * :class:`django.views.generic.base.View`
74 160
 
75  
-    **Notes**
  161
+    **Attributes**
  162
+
  163
+    .. attribute:: template_name_suffix
  164
+
  165
+        The CreateView page displayed to a GET request uses a
  166
+        ``template_name_suffix`` of ``'_confirm_delete'``.
  167
+
  168
+    **Example views.py**::
  169
+
  170
+        from django.views.generic.edit import DeleteView
  171
+        from django.core.urlresolvers import reverse_lazy
  172
+        from myapp.models import Author
76 173
 
77  
-    * The delete confirmation page displayed to a GET request uses a
78  
-      ``template_name_suffix`` of ``'_confirm_delete'``.
  174
+        class AuthorDelete(DeleteView):
  175
+            model = Author
  176
+            success_url = reverse_lazy('author-list')        
10  docs/ref/class-based-views/mixins-editing.txt
@@ -2,6 +2,16 @@
2 2
 Editing mixins
3 3
 ==============
4 4
 
  5
+The following mixins are used to construct Django's editing views:
  6
+
  7
+* :class:`django.views.generic.edit.FormMixin`
  8
+* :class:`django.views.generic.edit.ModelFormMixin`
  9
+* :class:`django.views.generic.edit.ProcessFormView`
  10
+* :class:`django.views.generic.edit.DeletionMixin`
  11
+
  12
+.. note:: Examples of how these are combined into editing views can be found at
  13
+    the documentation on ``Generic editing views``.
  14
+
5 15
 .. class:: django.views.generic.edit.FormMixin
6 16
 
7 17
     A mixin class that provides facilities for creating and displaying forms.

0 notes on commit dea554b

Please sign in to comment.
Something went wrong with that request. Please try again.