Setting the authenticated user on a Django model -


i have number of models need refer user created/updated them. involves passing request.user relevant attribute, i'd make automatic if possible.

there's extension doctrine (a php orm) called blameable set reference authenticated user when persisting model instance, e.g.:

class post {     /**      * set authenticated user on first persist($model)      * @orm\manytoone(targetentity="user", inversedby="posts")      * @gedmo\blameable(on="create")      */     private $createdby;      /**      * sets authenticated user on first , subsequent persists      * @orm\manytoone(targetentity="user")      * @gedmo\blameable(on="update")      */     private $updatedby; } 

to same functionality in django, first thought try , use pre_save signal hooks emulate - i'd need access request outside of view function (looks possible middleware bit hacky).

is there similar available django? better off explicitly passing authenticated user?

the level of decoupling django has makes impossible automatically set user in model instance.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -