#5247: ModelMultipleChoiceField doesn't select initial choices
--------------------------------------+-------------------------------------
Reporter: [email protected] | Owner: nobody
Status: new | Milestone:
Component: Forms | Version: SVN
Resolution: | Keywords:
ModelMultipleChoiceField SelectMultiple
Stage: Accepted | Has_patch: 1
Needs_docs: 0 | Needs_tests: 1
Needs_better_patch: 1 |
--------------------------------------+-------------------------------------
Comment (by anonymous):
Having ran into a similar problem I am wondering on the status of this
ticket. My situation is using a CheckboxSelectMultiple for a
ModelMultipleChoiceField with CheckboxSelectMultiple. Behaviour of this
combination seems fine with the notable exception of initial values, much
like the problem mentioned in this ticket. My fix is trivial to subclass
the checkbox widget thus:
class ModelCheckboxSelectMultiple(CheckboxSelectMultiple):
def render(self, name, value, attrs=None, choices=()):
# convert the 'value' into a list of pk values before rendering
forces the instances to unicode
if value is None:
value = []
selected_keys = []
for v in value:
selected_keys.append(v.pk)
return super(ModelCheckboxSelectMultiple, self).render(name,
selected_keys, attrs, choices)
Looking for direction on this and I would be happy to open a new ticket if
that makes sense.
--
Ticket URL: <http://code.djangoproject.com/ticket/5247#comment:17>
Django <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.