diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2010-01-10 19:23:42 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2010-01-10 19:23:42 +0000 |
| commit | 9bb1fa725154e6d1d0317fa0c48d7c240ad5e2d4 (patch) | |
| tree | 7b854676fbb2e321b61bb223c5f0a602bf70c8e6 /tests | |
| parent | 06645cbda783971287cdbfac67940c1982742bee (diff) | |
Fixed #9223 -- Added support for declarative widgets to ModelForm. I declare thanks to isagalaev.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12194 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/model_forms/models.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index ba59f9ae36..c488bf1659 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -287,6 +287,27 @@ Using 'fields' *and* 'exclude'. Not sure why you'd want to do this, but uh, >>> CategoryForm.base_fields.keys() ['name'] +Using 'widgets' + +>>> class CategoryForm(ModelForm): +... +... class Meta: +... model = Category +... fields = ['name', 'url', 'slug'] +... widgets = { +... 'name': forms.Textarea, +... 'url': forms.TextInput(attrs={'class': 'url'}) +... } + +>>> str(CategoryForm()['name']) +'<textarea id="id_name" rows="10" cols="40" name="name"></textarea>' + +>>> str(CategoryForm()['url']) +'<input id="id_url" type="text" class="url" name="url" maxlength="40" />' + +>>> str(CategoryForm()['slug']) +'<input id="id_slug" type="text" name="slug" maxlength="20" />' + Don't allow more than one 'model' definition in the inheritance hierarchy. Technically, it would generate a valid form, but the fact that the resulting save method won't deal with multiple objects is likely to trip up people not |
