User actions logging app

373 views
Skip to first unread message

Mario Gudelj

unread,
Feb 28, 2012, 4:35:50 PM2/28/12
to django...@googlegroups.com

Hi list,

I was wandering if someone could recomend an easy django app for logging user actions performed on models. I'd like to log changes logged in users make around the app.

Cheers,

m

akaariai

unread,
Feb 28, 2012, 5:59:18 PM2/28/12
to Django users
I think there are some apps out there. The first question however is
do you want to log "user a changed object b" or do you need an audit
trail also, that is do you need to have the information of user a
changed object b's field c from value "foo" to value "bar".

I really am not the one to tell you which app is the correct one. I
usually have a small create_log_entry() method for creating entries
for modifications, and database triggers for the audit trail. The
create_log_entry is often the right way to go, as more often than not
I want to set all changes to the "main" record. That is, if somebody
changes an article's attachment, it is the article that needs to have
the changed log entry, not the attachment.

The log entry model is something like this:
class LogEntry(object):
to_pk = models.IntegerField() #lets assume you are working only
with integer primary keys
to_type = models.CharField(max_length=40, choices=(('article',
'Article'), ...))
mod_type = choices "INSERT/UPDATE/DELETE"
who = FK(user)
what = models.TextField() # A "comment" for the edit
when = models.DateTimeField()
@classmethod
def create_log_entry(cls, to_obj, edit_type, user, what_done):
...

Combined with database-level triggers you can get a good audit trail.
I have some scripts to ease maintain the DB triggers for PostgreSQL
when using Django. I hope I will have some time to polish them for
release, I believe they could be some use for the community.

- Anssi

Babatunde Akinyanmi

unread,
Feb 29, 2012, 2:00:00 AM2/29/12
to django...@googlegroups.com
Yes, they definitely will.

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

--
Sent from my mobile device

Mario Gudelj

unread,
Feb 29, 2012, 8:12:19 AM2/29/12
to django...@googlegroups.com
Wow. Legend! That's so much Annsi.

akaariai

unread,
Feb 29, 2012, 9:49:26 AM2/29/12
to Django users
The log entry model above is very much like what is used in the Admin.
You might want to investigate that model, too, for logging who-did-
what. It can be found from django.contrib.admin.models.

The reason why I use my own is that I usually have some extra columns
related to the audit trail handling.

- Anssi

On Feb 29, 3:12 pm, Mario Gudelj <mario.gud...@gmail.com> wrote:
> Wow. Legend! That's so much Annsi.
>
> On 29 February 2012 18:00, Babatunde Akinyanmi <tundeba...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Yes, they definitely will.
>

akaariai

unread,
Mar 6, 2012, 8:52:54 AM3/6/12
to django...@googlegroups.com
On Wednesday, February 29, 2012 12:59:18 AM UTC+2, akaariai wrote:
Combined with database-level triggers you can get a good audit trail.
I have some scripts to ease maintain the DB triggers for PostgreSQL
when using Django. I hope I will have some time to polish them for
release, I believe they could be some use for the community.

I now have a _very_ experimental shadow table management project at:
https://github.com/akaariai/pgsql_shadow_tables

I ended up rewriting the project from scratch. The above version is purely plpgsql based, so it is usable in any project using PostgreSQL.

There are some nice features:
  - You have modification history available (well, duh).
  - You can "timetravel" your database.
  - After schema modifications, upgrading the shadow tables should be oneliner: select shadow_meta.update_shadow_schema('public');

See the README for more info. It might be a little hard to follow. As said, I have not used much time for polishing the project.

Once more: it is currently in very early stages. I do not use the scripts in production, and neither should you.

With some testing and some polishing I believe the project could be very useful for small write volume web-apps.

 - Anssi
Reply all
Reply to author
Forward
0 new messages