ModelForm enforces its version of save_m2m

129 views
Skip to first unread message

James Pic

unread,
May 22, 2012, 5:53:00 AM5/22/12
to django-d...@googlegroups.com
Hello everybody,

Currently, Django ModelForm enforces it's local version of save_m2m:
https://github.com/django/django/blob/38408f8007eae21b9f1cbbcc7f86d4b2042ff86a/django/forms/models.py#L76

As a result, users who want to overload save_m2m can not support
commit=False: https://github.com/yourlabs/django-autocomplete-light/blob/master/autocomplete_light/contrib/generic_m2m.py#L50

Wouldn't it be great if users could overload save_m2m ?

If you agree, I volunteer to do the ticket and pull request. Else I'll
leave my hack in my app :(

Regards

Stephen Burrows

unread,
May 25, 2012, 4:14:27 AM5/25/12
to django-d...@googlegroups.com
It's definitely possible for users to support commit=False. If you call form.save(commit=False), you can then store form.save_m2m in a temporary variable, define a new save_m2m function, and then call the old function from the new. Here's sort of an example: https://github.com/pculture/mirocommunity/blob/31688f2/localtv/user_profile/forms.py#L76. Does it a little differently, but the same result.

--Stephen

is_null

unread,
Jun 6, 2012, 5:08:24 AM6/6/12
to django-d...@googlegroups.com
Thanks for answering. It's "funny code" but it works indeed.

Thanks again
Reply all
Reply to author
Forward
0 new messages