Greetings,
I've been messing around with trying to update some custom forms to
instead be model forms, and I ran into something that struck me as odd.
ModelForm relies on the models fields to select a default form field,
and to save the returned form data. However the ManytoManyField does not
appear to have behavior for dealing with 'through' models. The
save_form_data just calls `set` on the ManyRelatedManager, which errors
out if a through model without auto_created=True is defined.
As far as I can tell I either have to write a lot of boiler plate in my
ModelForm (add a custom field, override the __init__, override save(),
etc), or define a custom ManyToManyField which overrides save_form_data.
This seems odd to me as the through model seems like the sensible place
for any behaviour required by the extra fields it defines.
The ManyToMany field has knowledge of everything needed to access the
intermediate model's default manager. It would make perfect sense to me
that to have to implement custom clear/add/remove methods on either the
model or it's manager for any through models that defined extra fields,
and then be able to plug-and-play with the ModelForm framework. So my
question is:
Is there any particular reason that save_form_data does not have some
default behavior for through models?
Cheers,
Andrew
--
This message has been scanned by E.F.A. Project and is believed to be clean.
--
You received this message because you are subscribed to the Google Groups "Django
developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/e1fe8354-e1d1-05a1-e433-6fcf7e46216a%40linear-systems.com.
For more options, visit https://groups.google.com/d/optout.