Opened 17 years ago
Closed 17 years ago
#6314 closed (wontfix)
ModelForm doesn't support MultiValueDict as initial argument
Reported by: | Ilya Semenov | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The following code works fine:
class MyForm(forms.Form): foo = forms.CharField() form = MyForm(initial=request.GET) # can be accessed as http://host/view/?foo=default_value
The following code does not fetch the values from request.GET:
class Foo: foo = models.CharField(max_length=255) class MyForm(forms.ModelForm): class Meta: model = Foo form = MyForm(Foo(), initial=request.GET) # does nothing
However, the following hack can be used to fetch the values from request.GET:
class Foo: foo = models.CharField(max_length=255) class MyForm(forms.ModelForm): class Meta: model = Foo form = MyForm(Foo(), initial=dict(request.GET.items())) # works as expected
Suggested behaviour: initial argument to ModelForm should accept MultiValueDict's, as the base Form implementation does.
Attachments (2)
Change History (5)
comment:1 by , 17 years ago
Has patch: | set |
---|---|
Summary: | ModelForm doesn't accept MultiValueDict as initial argument → ModelForm doesn't support MultiValueDict as initial argument |
Triage Stage: | Unreviewed → Accepted |
by , 17 years ago
Attachment: | 6314-1.diff added |
---|
by , 17 years ago
Attachment: | 6314-2.diff added |
---|
comment:2 by , 17 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:3 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
No, I don't think this is worth doing. There's no real use case for not just using a normal dictionary for the "initial" parameter. The example given in the ticket report isn't convincing, as GET data is designed to passed via the "data" parameter, not via "initial".
If somebody has a multi-value structure, they can do type the extra characters to convert it to something that is a dictionary proxy fairly easily, so we shouldn't have to add support for this in Django.
It's not so much that a MultiValueDict isn't accepted, but that its values will be seen as lists, since a dict.update() doesn't know what a MultiValueDict is.