No, this hasn't changed. Simply because separation of concern is an architectural principle of MVC (model-view-controller), which is also how Django (model-view-template) and most web frameworks with ORM are architected. Models know nothing about the request
, it's not available (and in many cases there isn't a request at all when a model is saved, think of management commands or regular tasks running in the background).
The alternative to thread local is to make sure you implement it yourself in the controller layer (view layer in Django):
- Create a view mixin that you can mix with all the generic views that use the
ModelFormMixin
to save the user into the model (ModelFormMixin.form_valid()
). Or combine it with a form mixin where the user is passed to the form (FormMixin.get_form_kwargs()
) and saved when the form is saved (ModelForm.save()
).
- Create a
ModelAdmin
mixin that does the same when saving a model in the django admin site.
This of course means someone on your team may forget to do it when creating new views and forms. The link you posted contains an answer as to the advantages and disadvantages of using thread local.