Ok, I'm heading for work now, will give it a spin this evening. Thanks everyone for your comments!
J On Tuesday, 11 August 2015 02:07:07 UTC+10, Tim Graham wrote: > > Yes, I agree that a documentation change should be sufficient (although I > still didn't look at the formsets situation). > > On Monday, August 10, 2015 at 11:57:19 AM UTC-4, Carl Meyer wrote: >> >> Hi Tim, >> >> On 08/10/2015 11:07 AM, Tim Graham wrote: >> > Yes, the idea is that ModelForm.save() method could become (after >> > deprecation finishes): >> > >> > def save(self): >> > """ >> > Save this form's self.instance object and M2M data. Return the >> model >> > instance. >> > """ >> > if self.errors: >> > raise ValueError( >> > "The %s could not be %s because the data didn't validate." >> % ( >> > self.instance._meta.object_name, >> > 'created' if self.instance._state.adding else >> 'changed', >> > ) >> > ) >> > self.instance.save() >> > self._save_m2m() >> > return self.instance >> > >> > Instead of calling super().save(commit=False) to retrieve >> form.instance, >> > you can just manipulate form.instance directly and then call >> > super().save(). I don't see a need for the _instance getters/setters >> you >> > proposed. >> > >> > There's also a deprecation checklist to help when writing a patch: >> > >> https://docs.djangoproject.com/en/1.8/internals/contributing/writing-code/submitting-patches/#deprecating-a-feature >> >> >> IMO this is an example of the sort of low-value deprecation of a >> widely-used API that gets people upset at us for wasting their time. >> >> I agree that .save(commit=False) isn't the best or best-named API ever, >> but it's been in Django since the beginning, it's _extremely_ widely >> used, and (having taught Django classes to new users), I don't think it >> ranks very high on the list of Django APIs that cause confusion in >> practice. >> >> I wouldn't mind an update to the docs to recommend manipulating >> `form.instance` and then calling `form.save()` (in place of `obj = >> form.save(commit=False); obj.save(); form.save_m2m()`). I don't think >> this requires any code changes; it's been true for a while (since >> model-validation I think?) that the actual instance-updating happens >> already in `_post_clean()`. >> >> This could put us on the path toward an eventual deprecation of >> `commit=False`, but I think we should be very slow to actually deprecate >> it. >> >> Carl >> >> -- 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 django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/934a01eb-03c1-40bf-a338-6e20c739bd5d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.