Discouraging the use of super() seems like a bad idea that could limit 
flexibility in the future. I think Django's documentation describes the 
behavior pretty well. Perhaps the Django Girls tutorial could be improved 
instead. I don't recall having trouble understanding how this worked when I 
learned Django and introducing a new way to duplicate functionality of a 10 
year old pattern doesn't seem worth it to me.

https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/#the-save-method

On Thursday, August 6, 2015 at 7:34:54 AM UTC-4, Javier Candeira wrote:
>
> Hi, I'm the author of Ticket #25227 Add utility method 
> `get_updated_model()` to `ModelForm` and its accompanying patch.
>
> Ticket: https://code.djangoproject.com/ticket/25227
>
> Patch: https://github.com/django/django/pull/5105
>
> Here's the writeup to save everyone a click:
>
> Add utility method get_updated_model() to ModelForm
>
> Additionally, add utility method get_updated_models() to FormSet
>
> Rationale:
>
> While doing the djangogirls tutorial, I noticed that 
> ModelForm.save(commit=False) is given to newcomers as a reasonable way to 
> acquire a form's populated model. This is an antipattern for several 
> reasons:
>
>   - It's counterintuitive. To a newcomer, it's the same as 
> ``save(save=no)``. 
>   - It's a leaky abstraction. Understanding it requires understanding that 
> the save method does two things: a) prepare the model, and b) save it to 
> the database.
>   - It doesn't name its effect or return well.
>
> All these problems are addressed in the current patch. Changes:
>
>  - Implement ModelForm.get_updated_model()
>  - Implement FormSet.get_updated_models()
>  - Refactor ModelForm.save() and FormSet.save() to allow the above.
>  - Both the tests and contrib.auth have been modified: any call to 
> save(commit=False) for the purpose of obtaining a populated model has been 
> replaced by get_updated_model(). Tests still pass, I'm confident it's a 
> successful refactor.
> - New tests have been added for the new methods in different contexts 
> (from a ModelForm, from a FormSet, etc).
>  - documentation has also been modified to showcase the new methods.
>
> Notes:
>
> Uses of ModelForm.save(commit=False) in the codebase have been left alone 
> wherever it was used for its side effects and not for its return value.
>
> The Djangogirls tutorial has a PR that depends on the changes in the 
> present one:
>
> https://github.com/DjangoGirls/tutorial/pull/450
>
>

-- 
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/9c5eb1c5-ce13-48ea-8fe9-af013e5e1d45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to