Ticket #6314: 6314-2.diff
File 6314-2.diff, 1.9 KB (added by , 17 years ago) |
---|
-
tests/modeltests/model_forms/models.py
325 325 >>> print f 326 326 <tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr> 327 327 328 The 'initial' argument to a ModelForm can be a MultiValueDict. 329 >>> from django.utils.datastructures import MultiValueDict 330 >>> f = CategoryForm(initial=MultiValueDict({'name': ['V1', 'V2']})) 331 >>> print f['name'] 332 <input id="id_name" type="text" name="name" value="V2" maxlength="20" /> 333 328 334 >>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.') 329 335 >>> art.save() 330 336 >>> art.id -
django/newforms/models.py
7 7 8 8 from django.utils.translation import ugettext_lazy as _ 9 9 from django.utils.encoding import smart_unicode 10 from django.utils.datastructures import SortedDict 10 from django.utils.datastructures import SortedDict, MultiValueDict 11 11 from django.core.exceptions import ImproperlyConfigured 12 12 13 13 from util import ValidationError, ErrorList … … 272 272 object_data = model_to_dict(instance, opts.fields, opts.exclude) 273 273 # if initial was provided, it should override the values from instance 274 274 if initial is not None: 275 object_data.update(initial) 275 if isinstance(initial, MultiValueDict): 276 for k, v in initial.items(): 277 object_data[k] = v 278 else: 279 object_data.update(initial) 276 280 BaseForm.__init__(self, data, files, auto_id, prefix, object_data, error_class, label_suffix) 277 281 278 282 def save(self, commit=True):