From 5c98223f39e5cf92c603a08e7ed70d57e565a5a3 Mon Sep 17 00:00:00 2001 From: Alasdair Nicol Date: Thu, 4 Jun 2015 16:19:57 +0100 Subject: [PATCH] Fixed #24191 -- Documented Form.changed_data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks rhertzog and Björn Påhlsson for the suggestion. --- docs/ref/forms/api.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 008170d341..34f8adbaec 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -250,8 +250,8 @@ precedence:: Url: Comment: -Checking if form data has changed ---------------------------------- +Checking which form data has changed +------------------------------------ .. method:: Form.has_changed() @@ -277,6 +277,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 ----------------------------------