I am struggling right now with the same concerns :-)
I have a hand-written form for a model with ManyToMany field.

So far, I noted a few things that helped me come to a working
solution, but maybe not really elegant...

The form initialization with an object looks like this (I hope...):
my_form = MyForm(initial=my_object.__dict__)
=> ManyToMany fields do not show up in that __dict__.

I had to add them by hand, turning the above one-liner into this:
initial_values = my_object.__dict__
initial_values.update({'m2m_field' = [obj.id for obj in
my_object.m2m_field.all()]})
my_form = MyForm(initial=initial_values)

To summarize, I built the list of ids from the ManyToMany relation to
my form, appending that list to the dict passed as initial data.

I am not really happy with that solution, maybe some more advanced
newforms user may lead a better way.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to