Wednesday, March 30, 2011

Re: model manager and request

Jacob,

This sort of thing comes up so frequently on this list that we've all
seen those answers dozens of times, although not usually in so concise
a manner.

My question, to which there seems to be no answer, is what a good
approach to do something that I know (from spending a long time on
this list) is also in high demand: Storing audit information.

Simple requirement:
Store datetime.now(), request.user, and changes to a model
automatically on post_save.

Problem:
The "correct" solutions do not work. If you're using any pluggable
apps at all you have to fork them or not log them. Refactoring is not
an option.

I understand why request information is simply not in scope in
models.py. This isn't a rant or a demand for a fundamental change to
the way Django works. I'm just looking for either:

1. A definitive "This is currently impossible in Django."

2. This is possible with this clever hack/middleware/pseudocode/whatever.

Obviously this method (should it exist) allows a lot of bad designs in
Django apps. But for the case of applying automatic logging in a
Django project, it seems like a reasonable desire. Especially given
that, as Django is a Web framework, there is always a request and
always a user (even if it's an anonymous user).

Your thoughts would be greatly appreciated. I'll also be attending
your webinar tomorrow. If you find this question to be in scope or
have extra time then I'd love to see it addressed.

Thank you,
Shawn

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment