How to enable logging of django rest api CRUD operations in django_admin_log?

I want to register all CRUD operations performed on objects of the Django model through a REST structure implemented as part of django rest. I am extending viewets.ModelViewSet to create my own viewSet class for defining REST API endpoints.

+5
source share
1 answer

There may be two different solutions ...

1.Use the signals in django to track each operation in CRUD and create another model, an instance of which is created for each signal. Something like this ....

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, the Notification is the model you made for logging changes.

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

0
source

Source: https://habr.com/ru/post/1204887/


All Articles