Ticket #6314: 6314-1.diff

File 6314-1.diff, 1.6 KB (added by Matt McClanahan, 17 years ago)
  • tests/modeltests/model_forms/models.py

     
    308308>>> print f
    309309<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr>
    310310
     311The '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
    311317>>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.')
    312318>>> art.save()
    313319>>> art.id
  • django/newforms/models.py

     
    272272            object_data = model_to_dict(instance, opts.fields, opts.exclude)
    273273        # if initial was provided, it should override the values from instance
    274274        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
    276280        BaseForm.__init__(self, data, files, auto_id, prefix, object_data, error_class, label_suffix)
    277281
    278282    def save(self, commit=True):
Back to Top