Adrian Holovaty wrote:
> 
> 
>>- we have automatic fields for createdate and updatedate (auto_now,
>>auto_now_add). what about automatically inserting the logged in user who
>>creates (or updates) the record? i don´t know about anybody else, but i need
>>that all the time. that´s especially interesting when using manipulators,
>>because with "request.user" you won´t have the ID of the user (if i´m right
>>here?).
> 
> 
> This currently isn't possible. Implementation suggestions are welcome!

This is getting asked with increasing frequency... The least bad way to
do this currently is with a middleware that records the current user
from the request in a thread local, and then fetch that in presave.
Pretty grotty.

The only reason LazyDate works as it does is because we have an implicit
global variable holding the current time.

So if we wanted to solve this cleanly, we would need to clear up what
the manipulator gets passed.

Currently, the manipulator gets passed a dictionary which is usually
request.POST + request.FILES. This is a bit manual right now.

It might be reasonable to pass in a Context argument, so that the
request processors could be reused.

Then the pre_save event handlers would get an extra context argument,
and could pull things out of that. We could provide a special subclass
of foreignkey for user that does this by default, ie pulls out
request.user and saves that as the value of the creator or whatever.

The other thing to sort out here is validation. It currently gets done
on the raw POST data which has some problems.

Reply via email to