summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-11-15 23:17:00 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-11-15 23:17:00 +0000
commit05420093ae9024aa94c773de6d6055ec2465d38b (patch)
tree45aeafe1ecf03f6b77adf94732ed3408ef8fb900 /tests/regressiontests
parentc4070e86c8067cbd615b6f1eb4f30098bd684da5 (diff)
newforms: Added unit test showing it's possible to construct the fields in a Form dynamically
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4074 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/forms/tests.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py
index 21bd378f1f..e63ca097f7 100644
--- a/tests/regressiontests/forms/tests.py
+++ b/tests/regressiontests/forms/tests.py
@@ -1194,8 +1194,22 @@ Form.clean() still needs to return a dictionary of all clean data:
>>> f.clean()
{'username': u'adrian', 'password1': u'foo', 'password2': u'foo'}
-
-
+It's possible to construct a Form dynamically by adding to the self.fields
+dictionary in __init__(). Don't forget to call Form.__init__() within the
+subclass' __init__().
+>>> class Person(Form):
+... first_name = CharField()
+... last_name = CharField()
+... def __init__(self):
+... super(Person, self).__init__()
+... self.fields['birthday'] = DateField()
+>>> p = Person()
+>>> print p
+<table>
+<tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr>
+<tr><td>Last name:</td><td><input type="text" name="last_name" /></td></tr>
+<tr><td>Birthday:</td><td><input type="text" name="birthday" /></td></tr>
+</table>
"""
if __name__ == "__main__":