ModelMultipleChoiceField doesn\'t select initial choices and I can\'t make the following fix (link below) work in my example:
http://code.djangoproject.com/ticket/52
I'm replying for 1)
1. How can I make ModelMultipleChoiceField take those "initial" values?
This could be done in your Action_Form
__init__
method using ModelMultipleChoiceField initial
attribute.
As it says in the Django source code (db/models/fields/related.py)
in def formfield(self, **kwargs)
:
# If initial is passed in, it's a list of related objects, but the
# MultipleChoiceField takes a list of IDs.
So you need to give it a list of IDs:
class Action_Form(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(Action_Form, self).__init__(*args, **kwargs)
self.fields['from_company'].initial = [c.pk for c in Contact.object.filter()]