diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-12-27 05:15:22 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-12-27 05:15:22 +0000 |
| commit | d853278253b5efa60a691ae9b83fb6352d2a91f0 (patch) | |
| tree | 625096f63ee85af332ed92238aab443f0ab2e857 /tests | |
| parent | 99723ac65a5471a619fc1a668391ee818cc1437d (diff) | |
newforms: Implemented formfield() for database ManyToManyField class and added unit tests
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4246 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/model_forms/models.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index 5ffd6aac9f..da10e215a6 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -101,6 +101,18 @@ Traceback (most recent call last): ... ValueError: The Category could not be created because the data didn't validate. +ManyToManyFields are represented by a MultipleChoiceField. +>>> ArticleForm = form_for_model(Article) +>>> f = ArticleForm(auto_id=False) +>>> print f +<tr><th>Headline:</th><td><input type="text" name="headline" maxlength="50" /></td></tr> +<tr><th>Pub date:</th><td><input type="text" name="pub_date" /></td></tr> +<tr><th>Categories:</th><td><select multiple="multiple" name="categories"> +<option value="1">Entertainment</option> +<option value="2">It's a test</option> +<option value="3">Third test</option> +</select></td></tr> + You can pass a custom Form class to form_for_model. Make sure it's a subclass of BaseForm, not Form. >>> class CustomForm(BaseForm): |
