Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17182 -- Changed best practice documentation for Form.clean to…

… use super() instead of relying on self.cleaned_data. Thanks, DrMeers.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17433 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 52d72a5a3e62ed8fde5796e0e131a8f7a5aefac3 1 parent faeee61
Jannis Leidel authored February 04, 2012

Showing 1 changed file with 5 additions and 2 deletions. Show diff stats Hide diff stats

  1. 7  docs/ref/forms/validation.txt
7  docs/ref/forms/validation.txt
@@ -300,7 +300,7 @@ example::
300 300
         ...
301 301
 
302 302
         def clean(self):
303  
-            cleaned_data = self.cleaned_data
  303
+            cleaned_data = super(ContactForm, self).clean()
304 304
             cc_myself = cleaned_data.get("cc_myself")
305 305
             subject = cleaned_data.get("subject")
306 306
 
@@ -316,6 +316,9 @@ example::
316 316
 In this code, if the validation error is raised, the form will display an
317 317
 error message at the top of the form (normally) describing the problem.
318 318
 
  319
+Note that the call to ``super(ContactForm, self).clean()`` in the example code
  320
+ensures that any validation logic in parent classes is maintained.
  321
+
319 322
 The second approach might involve assigning the error message to one of the
320 323
 fields. In this case, let's assign an error message to both the "subject" and
321 324
 "cc_myself" rows in the form display. Be careful when doing this in practice,
@@ -329,7 +332,7 @@ sample) looks like this::
329 332
         ...
330 333
 
331 334
         def clean(self):
332  
-            cleaned_data = self.cleaned_data
  335
+            cleaned_data = super(ContactForm, self).clean()
333 336
             cc_myself = cleaned_data.get("cc_myself")
334 337
             subject = cleaned_data.get("subject")
335 338
 

0 notes on commit 52d72a5

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