Storing user activity in Django

前端 未结 2 1642
暖寄归人
暖寄归人 2021-02-18 22:51

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

2条回答
  •  一整个雨季
    2021-02-18 23:26

    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.

提交回复
热议问题