How do you set the initial value for a ManyToMany field in django?

Posted by mlissner on Stack Overflow See other posts from Stack Overflow or by mlissner
Published on 2010-03-25T00:37:28Z Indexed on 2010/03/25 0:43 UTC
Read the original article Hit count: 370

Filed under:
|
|

I am using a ModelForm to create a form, and I have gotten the initial values set for every field in the form except for the one that is a ManyToMany field.

I understand that I need to give it a list, but I can't get it to work. My code right now is roughly:

contacts = userProfile.contact.all()
initial = {'contacts': contacts}

But that doesn't work. Am I missing something here?

© Stack Overflow or respective owner

Related posts about django

Related posts about manytomany