mirror of https://github.com/django/django.git
[1.8.x] Fixed #24191 -- Documented Form.changed_data
Thanks rhertzog and Björn Påhlsson for the suggestion.
Backport of 5c98223f39
from master
This commit is contained in:
parent
2358c1e5d7
commit
cccb7b49dc
|
@ -256,8 +256,8 @@ precedence::
|
||||||
<tr><th>Url:</th><td><input type="url" name="url" /></td></tr>
|
<tr><th>Url:</th><td><input type="url" name="url" /></td></tr>
|
||||||
<tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
|
<tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
|
||||||
|
|
||||||
Checking if form data has changed
|
Checking which form data has changed
|
||||||
---------------------------------
|
------------------------------------
|
||||||
|
|
||||||
.. method:: Form.has_changed()
|
.. method:: Form.has_changed()
|
||||||
|
|
||||||
|
@ -283,6 +283,16 @@ from what was provided in :attr:`~Form.initial` or ``False`` otherwise. The
|
||||||
result is computed by calling :meth:`Field.has_changed` for each field in the
|
result is computed by calling :meth:`Field.has_changed` for each field in the
|
||||||
form.
|
form.
|
||||||
|
|
||||||
|
.. attribute:: Form.changed_data
|
||||||
|
|
||||||
|
The ``changed_data`` attribute returns a list of the names of the fields whose
|
||||||
|
values in the form's bound data (usually ``request.POST``) differ from what was
|
||||||
|
provided in :attr:`~Form.initial`. It returns an empty list if no data differs.
|
||||||
|
|
||||||
|
>>> f = ContactForm(request.POST, initial=data)
|
||||||
|
>>> if f.has_changed():
|
||||||
|
... print("The following fields changed: %s" % ", ".join(f.changed_data))
|
||||||
|
|
||||||
Accessing the fields from the form
|
Accessing the fields from the form
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue