Ticket #6314: 6314-1.diff
File 6314-1.diff, 1.6 KB (added by , 17 years ago) |
---|
-
tests/modeltests/model_forms/models.py
308 308 >>> print f 309 309 <tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr> 310 310 311 The 'initial' argument to a ModelForm can be a MultiValueDict. 312 >>> from django.utils.datastructures import MultiValueDict 313 >>> f = CategoryForm(initial=MultiValueDict({'name': ['V1', 'V2']})) 314 >>> print f['name'] 315 <input id="id_name" type="text" name="name" value="V2" maxlength="20" /> 316 311 317 >>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.') 312 318 >>> art.save() 313 319 >>> art.id -
django/newforms/models.py
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 type(initial) == dict: 276 object_data.update(initial) 277 else: 278 for k, v in initial.items(): 279 object_data[k] = v 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):