Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing user activity in Django

I am looking to store the activity of an user, but I am not sure where to store it. I dont think database is a option as it will be very big than. I am looking to know as to how sites like facebook, dropbox remember all the activity of an particular user. And it can't be stored in sessions as this is not session specific rather user specific.

Please help me with your suggestion.

like image 324
Saransh Mohapatra Avatar asked Feb 21 '13 11:02

Saransh Mohapatra


1 Answers

Normally you can use Django Admin Logs for such an activity, if you want.

Normally Django keeps track of admin actions such as creating, updating or deleting existing records. It has the following structure:

from django.contrib.admin.models import LogEntry

LogEntry.objects.log_action(
                            user_id = ...,
                            content_type_id = ...,
                            object_id = ...,
                            object_repr = ....,
                            change_message = ...,
                            action_flag = ...
                           )

I am using that in my system as a logger, and keeping track of every action. Normally, Django logs insert, update or delete operations done over admin forms and I log my hand written view and form actions. Also, you can catch user operations such as login/logout using signals.

I defined new action flags. Django uses 3 flags: 1 for insert, 2 for update and 3 for delete. I expanded that list with my action flags.

The advantage of using this is, as I said, you do not need to handle default Django Admin forms and any action you did using these forms.

like image 99
FallenAngel Avatar answered Oct 17 '22 08:10

FallenAngel