mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #3114 -- newforms MultipleChoiceField now handles MultiValueDicts properly. Thanks for the patch, Honza Král
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4196 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
49f6d06c2f
commit
4add4e4272
3 changed files with 27 additions and 1 deletions
|
@ -1672,6 +1672,23 @@ MultipleChoiceField can also be used with the CheckboxSelectMultiple widget.
|
|||
<li><label><input checked="checked" type="checkbox" name="composers" value="P" /> Paul McCartney</label></li>
|
||||
</ul>
|
||||
|
||||
Data for a MultipleChoiceField should be a list. QueryDict and MultiValueDict
|
||||
conveniently work with this.
|
||||
>>> data = {'name': 'Yesterday', 'composers': ['J', 'P']}
|
||||
>>> f = SongForm(data)
|
||||
>>> f.errors
|
||||
{}
|
||||
>>> from django.http import QueryDict
|
||||
>>> data = QueryDict('name=Yesterday&composers=J&composers=P')
|
||||
>>> f = SongForm(data)
|
||||
>>> f.errors
|
||||
{}
|
||||
>>> from django.utils.datastructures import MultiValueDict
|
||||
>>> data = MultiValueDict(dict(name='Yesterday', composers=['J', 'P']))
|
||||
>>> f = SongForm(data)
|
||||
>>> f.errors
|
||||
{}
|
||||
|
||||
When using CheckboxSelectMultiple, the framework expects a list of input and
|
||||
returns a list of input.
|
||||
>>> f = SongForm({'name': 'Yesterday'}, auto_id=False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue