Changeset 4306
- Timestamp:
- 01/10/07 18:04:27 (2 years ago)
- Files:
-
- django/trunk/docs/newforms.txt (modified) (1 diff)
- django/trunk/tests/regressiontests/forms/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/newforms.txt
r4297 r4306 254 254 ... 255 255 AttributeError: 'ContactForm' object has no attribute 'clean_data' 256 257 ``clean_data`` will always *only* contain a key for fields defined in the 258 ``Form``, even if you pass extra data when you define the ``Form``. In this 259 example, we pass a bunch of extra fields to the ``ContactForm`` constructor, 260 but ``clean_data`` contains only the form's fields:: 261 262 >>> data = {'subject': 'hello', 263 ... 'message': 'Hi there', 264 ... 'sender': 'foo@example.com', 265 ... 'cc_myself': True, 266 ... 'extra_field_1': 'foo', 267 ... 'extra_field_2': 'bar', 268 ... 'extra_field_3': 'baz'} 269 >>> f = ContactForm(data) 270 >>> f.is_valid() 271 True 272 >>> f.clean_data # Doesn't contain extra_field_1, etc. 273 {'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'} 256 274 257 275 Behavior of unbound forms django/trunk/tests/regressiontests/forms/tests.py
r4304 r4306 1647 1647 >>> print p['birthday'] 1648 1648 <input type="text" name="birthday" id="id_birthday" /> 1649 1650 clean_data will always *only* contain a key for fields defined in the 1651 Form, even if you pass extra data when you define the Form. In this 1652 example, we pass a bunch of extra fields to the form constructor, 1653 but clean_data contains only the form's fields. 1654 >>> data = {'first_name': u'John', 'last_name': u'Lennon', 'birthday': u'1940-10-9', 'extra1': 'hello', 'extra2': 'hello'} 1655 >>> p = Person(data) 1656 >>> p.is_valid() 1657 True 1658 >>> p.clean_data 1659 {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 1649 1660 1650 1661 "auto_id" tells the Form to add an "id" attribute to each form element.
