#5247: ModelMultipleChoiceField doesn't select initial choices
-------------------------------------------------------+--------------------
Reporter: [EMAIL PROTECTED] |
Owner: nobody
Status: new | Component:
django.newforms
Version: SVN | Resolution:
Keywords: ModelMultipleChoiceField SelectMultiple | Stage:
Unreviewed
Has_patch: 1 | Needs_docs:
0
Needs_tests: 0 | Needs_better_patch:
0
-------------------------------------------------------+--------------------
Changes (by baumer1122):
* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
Comment:
OK, here's a better patch, although I'm not sure it is the right one. It
works for me but I'm not sure that testing for `_get_pk_val` is the best
way to determine whether we're working with a model instance or not.
Unfortunately, `django.db.models` can't be imported here to use
`isinstance`
Here is a simple test case for the problem:
models.py:
{{{
from django.db import models
class MyModel(models.Model):
name = models.CharField(max_length=100)
}}}
forms.py:
{{{
from django import newforms as forms
from myapp.models import MyModel
class MyForm(forms.Form):
my_field =
forms.ModelMultipleChoiceField(queryset=MyModel.objects.all())
}}}
{{{
from myapp import forms
from myapp.models import MyModel
MyModel.objects.create(name="one")
f = forms.MyForm({'my_field':MyModel.objects.all()})
f['my_field'].data #correct
f['my_field'].as_widget() #incorrect, without patch nothing is selected
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/5247#comment:5>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---