Ticket #6939: modeladmin_initial_parameters.diff
File modeladmin_initial_parameters.diff, 1.8 KB (added by , 17 years ago) |
---|
-
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 … … 254 254 object_data = model_to_dict(instance, opts.fields, opts.exclude) 255 255 # if initial was provided, it should override the values from instance 256 256 if initial is not None: 257 # If initial is an instance of MultiValueDict (or QueryDict), "flatten" it 258 if isinstance(initial, MultiValueDict): 259 initial = dict(initial.items()) 257 260 object_data.update(initial) 258 261 BaseForm.__init__(self, data, files, auto_id, prefix, object_data, error_class, label_suffix) 259 262 -
tests/modeltests/model_forms/models.py
596 596 <option value="4">Fourth</option> 597 597 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> 598 598 599 Use request data to initialize a form: 600 >>> class ArticleForm(ModelForm): 601 ... class Meta: 602 ... model = Article 603 >>> from django.http import QueryDict 604 >>> f = ArticleForm(initial=QueryDict('writer=3')) 605 >>> f.initial 606 {u'writer': u'3'} 607 599 608 # ModelChoiceField ############################################################ 600 609 601 610 >>> from django.newforms import ModelChoiceField, ModelMultipleChoiceField