diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-01-11 00:04:27 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-01-11 00:04:27 +0000 |
| commit | 73d62743e9cc27f09a5e30bcf7b0dbe64d6108de (patch) | |
| tree | 672686be7ab66b213033bcf3c6c1969076be7800 /docs | |
| parent | 963ccd7cb4c923a70dfcf4b321fa74a099c69948 (diff) | |
newforms: Added unit tests and docs explaining that clean_data will only ever contain fields of the form, even if extra fields are passed in data
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4306 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/newforms.txt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/newforms.txt b/docs/newforms.txt index b4da35ecd4..88485a7b8c 100644 --- a/docs/newforms.txt +++ b/docs/newforms.txt @@ -254,6 +254,24 @@ If your data does *not* validate, your ``Form`` instance will not have a ... AttributeError: 'ContactForm' object has no attribute 'clean_data' +``clean_data`` will always *only* contain a key for fields defined in the +``Form``, even if you pass extra data when you define the ``Form``. In this +example, we pass a bunch of extra fields to the ``ContactForm`` constructor, +but ``clean_data`` contains only the form's fields:: + + >>> data = {'subject': 'hello', + ... 'message': 'Hi there', + ... 'sender': 'foo@example.com', + ... 'cc_myself': True, + ... 'extra_field_1': 'foo', + ... 'extra_field_2': 'bar', + ... 'extra_field_3': 'baz'} + >>> f = ContactForm(data) + >>> f.is_valid() + True + >>> f.clean_data # Doesn't contain extra_field_1, etc. + {'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'} + Behavior of unbound forms ~~~~~~~~~~~~~~~~~~~~~~~~~ |
