Keeping track of which user did what

3 views
Skip to first unread message

Chris Farley

unread,
May 16, 2008, 8:15:14 AM5/16/08
to Django users
Django has that nice "auto_add=True" property you can set on a model's
field. I have two fields in my models called "created_at" and
"updated_at" that keeps track of each model instance's creation/
modification date. It's incredibly easy.

I also want to keep track of which user created/updated each instance.
Right now, I'm doing this from my views -- I just get the user from
the request object and manually populate my "created_by" and
"updated_by" fields. This definitely violates the DRY principle... I
would love to move this code into my model code (by maybe overriding
the save method), but I don't think I have access to the request
object in my models.

Any suggestions? Thanks!

Richard Dahl

unread,
May 16, 2008, 1:03:43 PM5/16/08
to django...@googlegroups.com
This can be done with the threadlocals middleware:
Reply all
Reply to author
Forward
0 new messages