Form.has_changed()
Use the has_changed()
method on your Form
when you need to check if the form data has been changed from the initial data.
1 2 3 4 5 6 7 | >>> data = { 'subject' : 'hello' , ... 'message' : 'Hi there' , ... 'sender' : 'foo@example.com' , ... 'cc_myself' : True } >>> f = ContactForm(data, initial = data) >>> f.has_changed() False |
When the form is submitted, we reconstruct it and provide the original data so that the comparison can be done:
1 2 | >>> f = ContactForm(request.POST, initial = data) >>> f.has_changed() |
has_changed()
will be True
if the data from request.POST
differs from what was provided in initial
or False
otherwise. The result is computed by calling Field.has_changed()
for each field in the form.
Please login to continue.