Django: ModelMultipleChoiceField doesn't select initial choices

前端 未结 4 1709
孤独总比滥情好
孤独总比滥情好 2020-12-05 17:44

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

4条回答
  •  醉话见心
    2020-12-05 18:38

    If previous answer wasn't straight-forward enough, I try to answer 1) again:

    1. How can I make ModelMultipleChoiceField take those "initial" values?

    You can leave Action_Form as it was in the original question, and just use this to render exactly what you want:

    >>> form4 = Action_Form(initial={'from_company': Contact.objects.all().values_list('id',flat=True)})
    >>> print form4['from_company']
    

提交回复
热议问题