mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
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
This commit is contained in:
parent
faeee611d6
commit
52d72a5a3e
@ -300,7 +300,7 @@ example::
|
|||||||
...
|
...
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = self.cleaned_data
|
cleaned_data = super(ContactForm, self).clean()
|
||||||
cc_myself = cleaned_data.get("cc_myself")
|
cc_myself = cleaned_data.get("cc_myself")
|
||||||
subject = cleaned_data.get("subject")
|
subject = cleaned_data.get("subject")
|
||||||
|
|
||||||
@ -316,6 +316,9 @@ example::
|
|||||||
In this code, if the validation error is raised, the form will display an
|
In this code, if the validation error is raised, the form will display an
|
||||||
error message at the top of the form (normally) describing the problem.
|
error message at the top of the form (normally) describing the problem.
|
||||||
|
|
||||||
|
Note that the call to ``super(ContactForm, self).clean()`` in the example code
|
||||||
|
ensures that any validation logic in parent classes is maintained.
|
||||||
|
|
||||||
The second approach might involve assigning the error message to one of the
|
The second approach might involve assigning the error message to one of the
|
||||||
fields. In this case, let's assign an error message to both the "subject" and
|
fields. In this case, let's assign an error message to both the "subject" and
|
||||||
"cc_myself" rows in the form display. Be careful when doing this in practice,
|
"cc_myself" rows in the form display. Be careful when doing this in practice,
|
||||||
@ -329,7 +332,7 @@ sample) looks like this::
|
|||||||
...
|
...
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = self.cleaned_data
|
cleaned_data = super(ContactForm, self).clean()
|
||||||
cc_myself = cleaned_data.get("cc_myself")
|
cc_myself = cleaned_data.get("cc_myself")
|
||||||
subject = cleaned_data.get("subject")
|
subject = cleaned_data.get("subject")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user