如何在django_admin_log中启用django rest api CRUD操作的日志记录?

时间:2022-11-19 19:20:48

I want to log all CRUD operations performed on Django Model Objects via REST framework implemented in django rest framework. I extend viewsets.ModelViewSet to create my custom viewSet class for defining REST API end points.

我想通过django rest框架中实现的REST框架记录在Django Model Objects上执行的所有CRUD操作。我扩展了viewsets.ModelViewSet来创建我的自定义viewSet类来定义REST API端点。

1 个解决方案

#1


1  

There can be two different solutions...

可以有两种不同的解决方案......

1.Use signals in django to keep track of each operation in CRUD and make different model whose instance is created for each signal.Something like this....

1.在django中使用信号来跟踪CRUD中的每个操作,并为每个信号创建实例的不同模型。这样的事情....

signals.py 
@receiver(post_save, sender= Sender_model)
def crud_log(sender,created,**kwargs):
    obj= kwargs.get('instance')
    recipient=User.objects.get()
            Notification.objects.create(
                recipient= recipient,
                comment= obj,
                send_by=obj.supporter,
                text= "%s has commented on %s" % (obj.supporter,obj.project)
            )
            return None

here Notification is a model made by you to keep log of changes.

这里的通知是您为保持更改日志而制作的模型。

2.another solution is to use django-simple-history.

2.另一个解决方案是使用django-simple-history。

#1


1  

There can be two different solutions...

可以有两种不同的解决方案......

1.Use signals in django to keep track of each operation in CRUD and make different model whose instance is created for each signal.Something like this....

1.在django中使用信号来跟踪CRUD中的每个操作,并为每个信号创建实例的不同模型。这样的事情....

signals.py 
@receiver(post_save, sender= Sender_model)
def crud_log(sender,created,**kwargs):
    obj= kwargs.get('instance')
    recipient=User.objects.get()
            Notification.objects.create(
                recipient= recipient,
                comment= obj,
                send_by=obj.supporter,
                text= "%s has commented on %s" % (obj.supporter,obj.project)
            )
            return None

here Notification is a model made by you to keep log of changes.

这里的通知是您为保持更改日志而制作的模型。

2.another solution is to use django-simple-history.

2.另一个解决方案是使用django-simple-history。