Django: How to create a user action log/trace with vizualization

Viewed 39

I am looking for a tool to track user actions like:

  • user logged in
  • user changed password
  • user got bill via email
  • user logged
  • user uploaded image
  • user send message ... which I can include into my Django project. Afterwards I want to build queries and ask the system stuff like:
  • how often did a user a message within a month
  • how often did a user login within a month
  • does the user uploaded any images

and I would like to have some kind of interface. (Like google analytics)

Any idea? I am pretty sure that this is a common task, but I could not find anything like this.

1 Answers

There are many ways to achieve that. Try reading this link first. Also, you can use LogEntry for tracking the creation, deletion, or changes of the models you have. Also, it shows you the information you need in the admin panel, or also you can use some other third-party packages.
Or you may want to create your own Model to create logs for your application and this link may help you, but do not reinvent the wheel and analyze your situation.

from django.contrib.admin.models import LogEntry, ADDITION

LogEntry.objects.log_action(
    user_id=request.user.pk,
    content_type_id=get_content_type_for_model(object).pk,
    object_id=object.pk,
    object_repr=force_text(object),
    action_flag=ADDITION
)
Related