diff options
| author | Alasdair Nicol <alasdair@thenicols.net> | 2015-06-04 16:19:57 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-06-04 13:52:15 -0400 |
| commit | cccb7b49dc2bfdbebae170ebfeee1abf2a731552 (patch) | |
| tree | d14bb78331729add1d75b801cd7b3ca4de687b42 /docs | |
| parent | 2358c1e5d771ab09ec555ffc8c3c46d56507293e (diff) | |
[1.8.x] Fixed #24191 -- Documented Form.changed_data
Thanks rhertzog and Björn Påhlsson for the suggestion.
Backport of 5c98223f39e5cf92c603a08e7ed70d57e565a5a3 from master
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/forms/api.txt | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 44987ab98c..10c8ff0473 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -256,8 +256,8 @@ precedence:: <tr><th>Url:</th><td><input type="url" name="url" /></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() @@ -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 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 ---------------------------------- |
