Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

newforms: Added a unit test that tests dynamic field addition with ba…

…se fields defined on the class

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4438 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 546f16d3232f4efc93c7eef0d88079f67d1d7d3d 1 parent c93686c
Adrian Holovaty authored January 27, 2007

Showing 1 changed file with 22 additions and 0 deletions. Show diff stats Hide diff stats

  1. 22  tests/regressiontests/forms/tests.py
22  tests/regressiontests/forms/tests.py
@@ -2312,6 +2312,28 @@
2312 2312
 <tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
2313 2313
 <tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
2314 2314
 
  2315
+>>> class MyForm(Form):
  2316
+...     default_field_1 = CharField()
  2317
+...     default_field_2 = CharField()
  2318
+...     def __init__(self, data=None, auto_id=False, field_list=[]):
  2319
+...         Form.__init__(self, data, auto_id)
  2320
+...         for field in field_list:
  2321
+...             self.fields[field[0]] = field[1]
  2322
+>>> field_list = [('field1', CharField()), ('field2', CharField())]
  2323
+>>> my_form = MyForm(field_list=field_list)
  2324
+>>> print my_form
  2325
+<tr><th>Default field 1:</th><td><input type="text" name="default_field_1" /></td></tr>
  2326
+<tr><th>Default field 2:</th><td><input type="text" name="default_field_2" /></td></tr>
  2327
+<tr><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
  2328
+<tr><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
  2329
+>>> field_list = [('field3', CharField()), ('field4', CharField())]
  2330
+>>> my_form = MyForm(field_list=field_list)
  2331
+>>> print my_form
  2332
+<tr><th>Default field 1:</th><td><input type="text" name="default_field_1" /></td></tr>
  2333
+<tr><th>Default field 2:</th><td><input type="text" name="default_field_2" /></td></tr>
  2334
+<tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
  2335
+<tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
  2336
+
2315 2337
 HiddenInput widgets are displayed differently in the as_table(), as_ul()
2316 2338
 and as_p() output of a Form -- their verbose names are not displayed, and a
2317 2339
 separate row is not displayed. They're displayed in the last row of the

0 notes on commit 546f16d

Please sign in to comment.
Something went wrong with that request. Please try again.