diff options
author | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-02 07:03:33 +0000 |
---|---|---|
committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-02 07:03:33 +0000 |
commit | fbf5eaac9460a0f97187b80c9ac16b9aa023802e (patch) | |
tree | 94569c7763cebdeafd3564e87f88a9a146387a16 /tests/modeltests | |
parent | e43ace720cad6e0f000332e9dc4cba8af4be3bf6 (diff) | |
download | django-fbf5eaac9460a0f97187b80c9ac16b9aa023802e.tar.gz |
Fixed #10349 -- Modified ManyToManyFields to allow initial form values to be callables. Thanks to fas for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10652 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
-rw-r--r-- | tests/modeltests/model_forms/models.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index 16b50145d7..c5795b7e56 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -613,6 +613,30 @@ Add some categories and test the many-to-many form output. <option value="3">Third test</option> </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> +Initial values can be provided for model forms +>>> f = TestArticleForm(auto_id=False, initial={'headline': 'Your headline here', 'categories': ['1','2']}) +>>> print f.as_ul() +<li>Headline: <input type="text" name="headline" value="Your headline here" maxlength="50" /></li> +<li>Slug: <input type="text" name="slug" maxlength="50" /></li> +<li>Pub date: <input type="text" name="pub_date" /></li> +<li>Writer: <select name="writer"> +<option value="" selected="selected">---------</option> +<option value="1">Mike Royko</option> +<option value="2">Bob Woodward</option> +</select></li> +<li>Article: <textarea rows="10" cols="40" name="article"></textarea></li> +<li>Status: <select name="status"> +<option value="" selected="selected">---------</option> +<option value="1">Draft</option> +<option value="2">Pending</option> +<option value="3">Live</option> +</select></li> +<li>Categories: <select multiple="multiple" name="categories"> +<option value="1" selected="selected">Entertainment</option> +<option value="2" selected="selected">It's a test</option> +<option value="3">Third test</option> +</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> + >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', ... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art) >>> new_art = f.save() |